我有两个对象:
{
"_id" : ObjectId("54be5f5528c13bfc3409e8c2"),
"name" : "Antonio",
"lastname" : "de Cabezón",
"by" : 1510,
"dy" : 1566,
"country" : "spain",
"genre" : [
"classical",
"baroque"
]
}
{
"_id" : ObjectId("54be5f5528c13bfc3409e8c1"),
"name" : "Guillaume-Antoine",
"lastname" : "Calvière",
"by" : 1695,
"dy" : 1755,
"country" : "france",
"genre" : [
"baroque"
]
}
当我执行db.currentdb.find({genre:' baroque'})时,它也会返回第一个对象。
我想只获取类型仅为" baroque"的对象。这样做的正确方法是什么?
答案 0 :(得分:7)
你可以尝试
db.currentdb.find({genre: ['baroque']})
另外,请查看文档:
https://docs.mongodb.org/manual/reference/method/db.collection.find/