我刚刚开始使用 MongoDB 和 RESTHeart api 服务器。
我希望用 MongoDB 替换我现有的数据库,并且现有数据库也从其余的 api 接收一个 json,我认为变化会很小。所以,下面是问题:
当我查询 MongoDB 时,这就是我得到的
{
"_collection-props-cached": false,
"_embedded": {
"rh:doc": [
{
"_etag": {
"$oid": "56ff559b7ea5c11edc8f93b7"
},
"_id": {
"$oid": "56ff559b7ea5c11edc8f93b6"
},
"_links": {
"self": {
"href": "/presence/active_watchers/56ff559b7ea5c11edc8f93b6"
}
},
"callid": "1-12285@10.0.1.168",
"contact": "sip:service@10.0.1.168:5060;transport=UDP",
"event": "presence",
},
{
"_etag": {
"$oid": "56ff55897ea5c11edc8f93b5"
},
"_id": {
"$oid": "56ff55897ea5c11edc8f93b4"
},
"_links": {
"self": {
"href": "/presence/active_watchers/56ff55897ea5c11edc8f93b4"
}
},
"callid": "1-12285@10.0.1.168",
"contact": "sip:service@10.0.1.168:5060;transport=UDP",
"event": "presence",
"event_id": "",
}
]
},
"_etag": {
"$oid": "56ff44807ea5c11edc8f93a6"
},
"_id": "active_watchers",
"_links": {
"curies": [],
"self": {
"href": "/presence/active_watchers"
}
},
"_returned": 2,
"descr": "subscriptions collection"
}
我只对rh_doc数组感兴趣。我的问题是,有没有一种方法可以让我只接收来自 Monogo 的文件而无需额外的信息。
问题是,现有代码只需要像这样的值数组,[{callid:"123",...},{callid:"234",...}]
并且它已经使用 cJSON 在 C 中以这种方式编码。触摸C代码感觉很可怕!
或者如果 CJSON 可以删除键:_etag、_id等。
编辑 这是我查询的方式:
http GET "http://localhost:8080/presence/active_watchers?filter={'presentity_uri':'sip:service-1@opensipstest.org'}&filter={'event':'presence'}"
谢谢