RESTHEART查询嵌套数组子图



i m与Mongodb和Restheart合作。

在我的nosql db中,我有一个具有此结构的唯一文档:

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

如何构建一个URL Query,以使用户具有ID 11?

使用mongo shell应该是这样的东西:

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

我在Restheart上找不到类似的东西。

有人可以帮我吗?

使用此

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

RESTHEART返回所有文件:用户ID 11和12。

您的请求是针对文档资源的,即url是 http://myHost:port/documents/docID

filter 查询参数适用于收集请求,即诸如 http://myHost:port/documents

之类的URL

在任何情况下,您都需要投影(查询参数(才能限制返回的属性。

您应该使用以下请求(我没有尝试过(使用$ elementMatch投影操作员:

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

最新更新