I'm having trouble retrieving values โโfrom the requested documents in MongoDB.
For example, the structure of the document is similar:
{ "_id": { "$oid": "50f93b74f9eccc540b302462" }, "response": { "result": { "code": "1000", "msg": "Command completed successfully" }, "resData": { "domain:infData": { "domain:name": "ritesh.com", "domain:crDate": "2007-06-15T12:02:36.0000Z", "domain:exDate": "2013-06-15T12:02:36.0000Z" } } } }
And request code:
DBCollection collection = db.getCollection("domains"); BasicDBObject p = new BasicDBObject("response.resData.domain:infData.domain:name", "ritesh.com"); DBCursor c = collection.find(p); while(c.hasNext()) { DBObject obj = c.next(); Object value = obj.get("response.resData.domain:infData.domain:name"); }
It queries and retrieves the document, but I cannot figure out how to extract the value of "response.resData.domain: infData.domain: name" or other similar nested values โโfrom DBObject (or BasicDBObject since c.next () returns the type BasicDBObject).
I could get objects one at a time, for example:
((DBObject)obj.get("response")).get("resData")....
but it seems very cumbersome.
I thought, since you can put () the value of a nested field in BasicDBObject, for example:
basicDBObject.put("response.resData.domain:infData.domain:name", "ritesh.com");
so that I can use get () in the same way to extract from a BasicDBObject result using the same key. As I tried to do in the code above:
Object value = obj.get("response.resData.domain:infData.domain:name");
But this returns a null value.
This is probably something direct, but I can not understand it. And wherever I checked on the network, examples only extract values โโthat are not nested from the result. how
doc.get("name");
instead of something like:
doc.get("name.lastname.clanname");
Any help would be greatly appreciated. Thanks!