【发布时间】:2020-05-13 18:46:02
【问题描述】:
我正在学习 MongoDB,并尝试使用 MongoDB 客户端按特定键值检索对象。
我有这些数据:
{
"type": "products",
"products": {
"Intel® Core™ i9-9980XE Extreme Edition": {
"description": null,
"price": 2457,
"catalog_id": "1"
},
"Intel® Core™ i9-9980HK": {
"description": null,
"price": 1548,
"catalog_id": "1"
},
"AMD Ryzen Threadripper 2990WX": {
"description": null,
"price": 500,
"catalog_id": "2"
},
"Baikalel Ectronics BE-M1000": {
"description": null,
"price": 128,
"catalog_id": "3"
},
"GeForce RTX 2080 Ti": {
"description": null,
"price": 2048,
"catalog_id": "5"
}
}
}
我已经了解了如何访问嵌套对象中的数据:
db.shop.findOne( { type : "products" }).products["GeForce RTX 2080 Ti"].price
但我有点困惑如何让 "catalog_id": "1" 过滤所有 hested 对象
当我使用时
db.shop.find( { type : "products" }, {"catalog_id": "1"})
MongoDB 客户端只显示主对象的 id。
【问题讨论】: