简体   繁体   English

Restheart查询嵌套数组子文档

[英]Restheart query for an nested array subdocument

I m working with mongodb and restheart. 我正在与mongodb和restheart一起工作。

In my nosql db i have a unique document with this structure: 在我的nosql数据库中,我有一个具有以下结构的唯一文档:

{
"_id": "docID",
"users": [
            {
             "userID": "12",                 
             "elements": [
                         {
                          "elementID": "1492446877599",
                          "events": [
                                     {
                                      "event1": "one"
                                     },   
                                     {                                       
                                      "event2": "two",
                                      }
                                     ]
                           }
               },
              {
             "userID": "11",                 
             "elements": [
                         {
                          "elementID": "14924",
                          "events": [
                                     {
                                      "event1": "one"
                                     },   
                                     {                                       
                                      "event2": "two",
                                      }
                                     ]
                           }
               }  

              ]  
}

how can i build an url-query in order to get the user with id 11? 我如何建立一个URL查询以获取ID为11的用户?

Using mongo shell it should be something like this one: 使用mongo shell应该是这样的:

db.getCollection('collection').find({},{'users':{'$elemMatch':{'userID':'12'}}}).pretty()

I cannot find anything similar on restheart. 我无法在安息心上找到任何类似的东西。

Could someone help me? 有人可以帮我吗?

Using this 使用这个

http://myHost:port/documents/docID?filter={%27users%27:{%27$elemMatch%27:{%27userID%27:%2712%27}}}

restheart returns me all the documents: userID 11 and 12. restheart会向我返回所有文档:userID 11和12。

Your request is against a document resource, ie the URL is http://myHost:port/documents/docID 您的请求针对文档资源,即URL为http://myHost:port/documents/docID

The filter query parameter applies for collection requests, ie URLs such as http://myHost:port/documents filter查询参数适用于收集请求,即URL,例如http://myHost:port/documents

In any case you need to projection (the keys query parameter) to limit the returned properties. 无论如何,您都需要投影( 查询参数)以限制返回的属性。

You should achieve it with the following request (I haven't tried it) using the $elementMatch projection operator : 您应该使用$ elementMatch投影运算符 ,通过以下请求(我尚未尝试)实现它:

http://myHost:port/documents?keys={"users":{"$elemMatch":{"userID":"12"}}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM