[英]How can I query multiple collections in mongodb at the same time?
books
{
name: "random",
stars: 4,
},
{
name: "random",
stars: 2,
}
foods
{
name: "random",
stars: ,
},
{
name: "random",
}
movies
{
name: "random",
stars: 0,
},
{
name: "random",
stars: 7,
}
got this collections in my database called dbcosos and I wanna get the items who had more than 3 stars could someone give me a hand?在我的名为 dbcosos 的数据库中得到了这个集合,我想得到超过 3 星的项目有人可以帮我吗?
You can't fetch data from multiple collections in a single query.您无法在单个查询中从多个集合中获取数据。 Instead u can use find() in this case to get the required result.相反,您可以在这种情况下使用find()来获得所需的结果。
let bookData = await booksSchema.find({$and:[{stars:{$exsits: true}},{stars:{$gte:3}}]})
Do same thing for foods
and movie
collection as well.And $exists
operator is used since it looks like stars
is an optional field.对foods
和movie
收藏也做同样的事情。使用$exists
运算符,因为它看起来像stars
是一个可选字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.