Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从MongoDB结果中去掉额外的json键_Json_Mongodb_Restheart_Cjson - Fatal编程技术网

如何从MongoDB结果中去掉额外的json键

如何从MongoDB结果中去掉额外的json键,json,mongodb,restheart,cjson,Json,Mongodb,Restheart,Cjson,我刚刚开始使用MongoDB和RESTHeartAPI服务器 我希望用MongoDB替换我现有的DB,并且现有的DB也从RESTAPI接收json,我认为变化不大。因此,问题如下: 当我查询MongoDB时,我得到的是 { "_collection-props-cached": false, "_embedded": { "rh:doc": [ { "_etag": {

我刚刚开始使用MongoDB和RESTHeartAPI服务器

我希望用MongoDB替换我现有的DB,并且现有的DB也从RESTAPI接收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可以删除键:\u etag、\u id

编辑 我是这样问的:

http  GET "http://localhost:8080/presence/active_watchers?filter={'presentity_uri':'sip:service-1@opensipstest.org'}&filter={'event':'presence'}"

谢谢

在find语句的第二个参数中,您可以指定要包括哪些字段

例如

或者,如果您只需要嵌套的rh:docs字段:

db.someCollection.find({}, {"_embedded.rh:doc": 1})

如果我没弄错的话,您可能想使用“如何查询集合”来获得当前结果?@MarkusWMahlberg谢谢。我想这是必须的,我现在正在研究它。@JoachimIsaksson我已经用我试图查询的URI编辑了这篇文章。谢谢John<代码>{u embedded:1}给出了0个结果,因此我尝试了
{u embedded:0}
,这给出了输出,但当我尝试使用restheart进行相同操作时,在这两种情况下都得到了0个文档<代码>{“{u collection-props-cached”:false,{u etag:{“$oid:“56ff44807ea5c11edc8f93a6”},“{u id:“活动的观察者”,“链接”:{“居里”:[],“自我”:“{”href:“/存在/活动的观察者?过滤器={u嵌入的.rh:doc':'1'}},{u返回:0,“描述”:“subscriptions collection”}addkeys={u-embedded':1}作为您对restheart的请求的get参数。我尝试了
keys={u-embedded':1}
keys={u-embedded.rh:doc':1}“
使用
&np
我得到的要么是问题中的完整文档,要么只是属性键,而不是实际键。不知道我做错了什么。使用
http://localhost:8080/presence/active_watchers?filter={'presentity_uri':'sip:service-1@opensipstest.org“}&filter={'event':'presence'}&np&keys={'u id':0}&keys={'u etag':0}
我可以删除不需要的属性。是的,之前我正在开发1.1.7版,现在我把它改为2.0.0测试版
db.someCollection.find({}, {"_embedded.rh:doc": 1})