【发布时间】:2014-04-16 09:52:12
【问题描述】:
我想查询 mongodb 文档以返回特定文档
假设我有以下文档,我只想搜索给定房间的具体细节。比如说,我想要查询返回 room_num = 210 的注释。我该怎么做?
我可以通过 db.locations.findOne({"facility.room.room_num" : room_num}); 进行查询 我不知道如何投影房间。 概括问题,我如何仅投影嵌入文档的特定条目。
我的文档是这样的--->
{
_id: Object("xxx"),
name: "Campus",
facilities: [
{ name : "Science",
rooms : [
{
room_num: 210,
notes: "Chemistry Lab 1",
Dimension: "x*x"
},{
room_num: 120,
notes: "Chemistry Lab 2",
Dimension: "x*x"
}
]
},
{ name : "Arts",
rooms: [
{
room_num: 90,
notes: "Drawing 1",
Dimension: "x*x"
},{
room_num: 100,
notes: "Drawing 2",
Dimension: "x*x"
}
]
}
]
【问题讨论】:
-
你希望得到什么格式?
-
我希望得到这个 {room_num: 210, notes: "Chemistry Lab 1", Dimension: "x*x" }
标签: javascript mongodb mongodb-query