i am new to mongoDB. I am using mongoDB in web app.
I want to know how to get the value of inner document attribute of a document.
Lets say my JSON is like,
{ "_id" : { "$oid" : "4ceb753a70fdf877ef5113ca"}, "Attrr1" : "value1", "Attr2": {"innerAttr1":"innerValue1", "innerAttr2":"innerValue2"}, "Attr3" : { "innerAttr3" : "innerValue3", "innerAttr4" : "innerValue4"} }
For the above json, how can i get innerValue1 and both innerValue1 & innerValue2.
I tried this, but its not working for me!!!
BasicDBObject innerQuery = new BasicDBObject();
field.put("Attr2.innerAttr1", 1);
Any suggestions would be appreciative!!!
Thanks
i am not get you. You need get value or set or add into collection inside of some document?
As i understand you using some driver for mongo db in java. I am not experienced in mongo driver for java. But i know ho to do this in driver or c#:
in c# mongo driver for update inner property in collection you need do following:
if query from above code retun one document – innerAttr1 property from Attr2 collection will be update. If i know that query return more than one document and i need update more tha one document i use such code:
I belive that the same logic in mongo driver for java.
Hope this help.