如何查找具有共同'类别'
的所有文档以下是我的示例文档。如何获取类别中常见的文档?
{
"_id": {
"$oid": "59b7fcace893d0450c44ada3"
},
"title": "Tesla model 3 questions",
"category": "movie",
"questionAndAnswers": '',
"__v": 0
}
{
"_id": {
"$oid": "59c4e12fd5276138f41c0896"
},
"title": "SpaceX Quiz",
"category": "Science",
"questionAndAnswers": '',
"__v": 0
}
{
"_id": {
"$oid": "59c4e12fd5276138f41c0890"
},
"title": "Nasa Quiz",
"category": "Science",
"questionAndAnswers": '',
"__v": 0
}
答案 0 :(得分:2)
db.collection.find({"category": "Science"})
将返回一个光标,您可以迭代该光标以获取所有文档" category"是"科学"。
答案 1 :(得分:1)
只需使用where category == 'theCommonCategory'.
它将为您提供具有CommonCategory的所有文档。