我现在学习MongoDB已有几个星期了,但我仍然不知道如何在我的项目中查询嵌套文档.我阅读了MongoDB文档,并在Google上搜索了很多,但是没有找到关于我的问题的好的解释或教程.也许你可以帮我!
i'm learning MongoDB for a few weeks now and i have still no idea how to query nested documents in my project. I read the MongoDB-docs and googled a lot, but i found no good explanations or tutorials for my problem. Maybe you can help me!
我有一个具有以下结构的Collection(此处为JSON输出):
I have a Collection with the following structure (here the JSON output):
{ community: "1", date: 1365680790125, isIndoor: "true", party: { teams: [ { isWinner: true, players: [ { name: "jim", hits: 4, isFinisher: true }, { name: "john", hits: 6, isFinisher: false } ] }, { isWinner: false, players: [ { name: "mike", hits: 6, isFinisher: false }, { name: "moe", hits: 3, isFinisher: false } ] } ] }, id: "3141be7f9988d872" }现在我想获取吉姆"参加的所有记录.
And now I want to get all records where 'jim' participated.
我尝试了此查询(在coffeescript中),但没有任何结果,我认为它非常糟糕...
I tried this query (in coffeescript), but i get no results and i think its very crappy...
query = party: $all:[ teams: $in: [ player: [ name: 'jim' ] ] ]希望您能帮助我理解查询嵌套文档. 谢谢!
I hope you can help me understand querying nested documents. Thanks!
推荐答案使用点标记以查询嵌入对象的字段:
Use dot notation to query against the fields of embedded objects:
query = { 'party.teams.players.name': 'jim' }更多推荐
查询嵌套在mongoDB中
发布评论