2017-04-17 121 views
0

我mongodb和restheart工作。Restheart查询嵌套数组子文档

在我的NoSQL数据库我有这个结构的独特文件:

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

       ] 
} 

我怎样才能以取得编号为11的用户建立一个URL查询?

使用蒙戈外壳应该是这样的一个:

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

回答

0

您的要求是对一个文档资源,即URL是http://myHost:port/documents/docID

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

无论如何您需要投影(查询参数)来限制返回的属性。

您应该具有以下要求实现它(我还没有尝试过),使用$elementMatch projection operator

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