查询嵌套在mongoDB中

编程入门 行业动态 更新时间:2024-10-18 10:19:57
本文介绍了查询嵌套在mongoDB中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我现在学习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中

本文发布于:2023-10-23 05:36:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519948.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   mongoDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!