I pull the following document from MongoDB into Java:
{
"_id": {
"$oid": "5076371389d22e8906000000"
},
"item": {
"values": [
{
"value1": [
4958,
3787,
344
],
"value2": [
4,
13,
23
]
}
],
"name": "item1"
}
}
Using
M mongo = new M("database", "collection");
String query = "{\"item.name\":\"item1\"}";
DBCursor cur = mongo.collection.find(mongo.query(query));
while(cur.hasNext()) {
System.out.println(cur.next().toString());
// I need to access value1 array.
}
I need to access value1 array, I also need to pull the whole document, so I cannot just ask Mongo to return this for me. Its like I am pulling this document, need to do a calculation and use the document again.
I understand this result can be converted to a map. But how would I be able to navigate through it since it is a multidimentional object. Thanks
Try this:
You can optimise it, but I hope you get the point and it helps.
cheers