【发布时间】:2015-10-09 03:31:54
【问题描述】:
我的 MongoDB 数据库中目前有一些文档包含此模板:
{
"_id": {
"$oid": "5616b757e4b0d2d408b39097"
},
"username": "admin",
"hash": "encrypted",
"salt": "salt",
"mail": "mail@mail.com",
"answered": {
"x": 203,
"y": 102
}
}
我想像这样使用 REST api 进行搜索:
https://api.mongolab.com/api/1/databases/[REDACTED]/collections/users?q={"username":"admin"}&f={"answered":1}&apiKey=[已编辑]
这正确地给了我
[ { "answered" : { "x" : 203 , "y" : 102 } } ]
这很好,但我想更深入地搜索“已回答”字段,如下所示:
https://api.mongolab.com/api/1/databases/[REDACTED]/collections/users?q={"username":"admin"}&f={"answered":{x:1}}&apiKey=[已编辑]
但这会出错,我尝试了几种变体,但它们都不起作用,documentation 没有说明它应该如何在 URL 中格式化。
我最终想要的是:
[ { "answered" : { "x" : 203 } } ]
【问题讨论】:
-
试试
{"answered.x": 1}?