0

I have just started using MongoDB and RESTHeart api server.

I wish to replace my existing DB with MongoDB and existing DB too receives a json from the rest api, I thought the change would be little. So, below is the issue:

When I query MongoDB, this is what I get

{
    "_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"
}

I am only interested in rh_doc array. My question is, is there a way I can just receive just the documents from the Monogo without the extra information.

The problem is, existing code expects just the array of values like [{callid:"123",...},{callid:"234",...}]and it has been coded that way in C using cJSON. It feels scary to touch the C code!!

Or may be if CJSON can delete the keys: _etag, _id etc.

Edit This is how I query:

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

Thanks

Jardanian
  • 711
  • 1
  • 6
  • 11

1 Answers1

0

In the second argument of your find statement you can specify which fields to include.

E.g.

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

Or if you only want the nested rh:docs field:

db.someCollection.find({}, {"_embedded.rh:doc": 1})
John Chang
  • 131
  • 2
  • Thanks John. `{_embedded: 1}` gives 0 results so I tried `{_embedded: 0}`, this gives the output but when I try same using restheart I get 0 documents in both case. `{ "_collection-props-cached": false, "_etag": { "$oid": "56ff44807ea5c11edc8f93a6" }, "_id": "active_watchers", "_links": { "curies": [], "self": { "href": "/presence/active_watchers?filter={'_embedded.rh:doc':'1'}" } }, "_returned": 0, "descr": "subscriptions collection" } ` – Jardanian Apr 02 '16 at 14:13
  • Add keys={'_embedded':1} as a get parameter to your request to restheart. – John Chang Apr 02 '16 at 15:40
  • I tried `keys={'_embedded':1}`and `keys={'rh:doc':1}"` and `keys={'_embedded.rh:doc':1}"` and with `&np` what I get is either the full document as in the question or I get just the properties keys and not the actual keys. Don't know what wrong I am doing. – Jardanian Apr 02 '16 at 19:25
  • Using `http://localhost:8080/presence/active_watchers?filter={'presentity_uri':'sip:service-1@opensipstest.org'}&filter={'event':'presence'}&np&keys={'_id':0}&keys={'_etag':0}` I am able to remove the unwanted properties. And yes earlier I was working on version **1.1.7** now I changed it to **2.0.0 beta** – Jardanian Apr 02 '16 at 20:41