[英]How can I update 2 collections at the same time using Node.js/Mongoose/MongoDB
[英]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,
}
在我的名为 dbcosos 的数据库中得到了这个集合,我想得到超过 3 星的项目有人可以帮我吗?
您无法在单个查询中从多个集合中获取数据。 相反,您可以在这种情况下使用find()来获得所需的结果。
let bookData = await booksSchema.find({$and:[{stars:{$exsits: true}},{stars:{$gte:3}}]})
对foods
和movie
收藏也做同样的事情。使用$exists
运算符,因为它看起来像stars
是一个可选字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.