[英]Get all documents with specific properties in MongoDB
大家早上好,
今天我面临 mongoose 查询。
假设我们有以下集合:
[
{letter: "A", name: "Books", action: "read"},
{letter: "B", name: "Notebook", action: "write"},
{letter: "C", name: "Camera", action: "take photos"},
{letter: "D", name: "Pencil", action: "draw"}
]
我想获得一个子集合,其中包含名称为:“书籍”和名称为:“铅笔”的文件。
所需的 output:
[
{letter: "A", name: "Books", action: "read"},
{letter: "D", name: "Pencil", action: "draw"}
]
是否可以使用“find()”方法?
使用$or
运算符的find
的另一个版本。
db.collection.find({
$or: [
{
"name": "Books"
},
{
"name": "Pencil"
}
]
})
这是为您准备的MongoPlayground 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.