I have mongo object like
{
"name" : "mongo",
"values" : [
{
"date" : "02-23-2015",
"price" : "5"
},
{
"date" : "02-23-15",
"price" : "6"
},
{
"date" : "02-22-15",
"price" : "7"
}
]
}
I am working with Java driver and I am able to extract this object with a query like:
QueryBuilder builder = new QueryBuilder();
DBObject nameQuery = new BasicDBObject("name", "mongo");
builder.and(nameQuery);
DBObject fullQuery = builder.get();
However what I want is to extract all of the price values and I want to store these in an array- right now I am only able to return this entire object..iterating through subsets like this is not explained very well in documentation, one example would be helpful.
Any help would be appreciated.
EDIT: ok now I am able to iterate through the objects in this array but it does not take advantage of mongo built ins and will naturally be slower:
while (curs.hasNext())
{
DBObject o = curs.next();
BasicDBList values = (BasicDBList) o.get("values");
BasicDBObject[] valuesArray = values.toArray(new BasicDBObject[0]);
for(BasicDBObject dbObj : valuesArray) {
name = dbObj.getString("name");
}
}
This allows me to extract whatever I want but I know there is a more efficient way. Any help would be great, thanks
Aucun commentaire:
Enregistrer un commentaire