查询Mongo中的嵌套列表存在

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

我在Mongo中有一个文档,其结构如下:

I have a document in Mongo that is structured in the following way:

{ "_id" : ObjectId("4eea7237d0ba3a04f20008fb"), "code" : "b2677c2809c844cc9d7e3e4ff8d95b46", "city_id" : 4, "datetime" : ISODate("2011-12-13T18:41:44.062Z"), "plays" : [ { "play_id" : 717224, "clicks" : [ ], "order" : 1, "mysql_id" : 145 }

我想查询其播放的文档。 clicks属性是一个非空列表。我试过没有运气的存在。我认为这样的事情可能有用:

I want to query for docs whose plays.clicks attribute is a non-empty list. I've tried exists with no luck. I thought that something like this might work:

db.collection.find({plays.clicks.0: {$exists:true}})

但我相信这只会返回播放数组中第一个元素包含的文档非空的点击列表。

But I believe that this would return only docs whose first element in the plays array contains a non-empty clicks list.

我是否想过如何完成这项工作?

Any thought on how I might get this done?

谢谢

推荐答案

db.collection.find({plays.clicks.0:{$ exists:true}})

是正确的语法,但是当播放是一个列表,查询将匹配任何 c>点击的文件 。没有办法以这种方式为子元素检索数组的子集[1]。有一个子/虚拟馆藏票[2]

is the right syntax, however as plays is a list the query will match any document that has clicks in plays. There is no way to retrieve a subset of an Array for subelements in this way[1]. There is a ticket for sub / virtual collections[2]

[1] www.mongodb/display/DOCS/Retrieving+a+Subset+of+Fields#RetrievingaSubsetofFields-RetrievingaSubrangeofArrayElements

[2] https:// jira .mongodb / browse / SERVER-828

更多推荐

查询Mongo中的嵌套列表存在

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

发布评论

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

>www.elefans.com

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