我有来自MongoDB数据库的这些数据,我想返回数组中的所有对象" Books"以及如何查询此数组中的特定书籍?
{
"_id": {
"$oid": "5b193757fb6fc05a6fe42330"
},
"Books": [
{
"Me Talk Pretty One Day ": {
"_id": 312
}
},
{
"One Hundred Years of Solitude ": {
"_id": 123
}
}
]
}
答案 0 :(得分:1)
如果您想从阵列中检索特定图书,可以试试这个
db.collection.find({
Books: {
$elemMatch: {
"Me Talk Pretty One Day": {
$exists: true
}
}
}
},
{
Books: {
$elemMatch: {
"Me Talk Pretty One Day": {
$exists: true
}
}
}
})