I am querying a Mongo DB in Scala and looping through the returned elements, that look like this:
{ "_id" : "123:1350918540586068000:v" ,
"i" : {
"vendorStyle" : "coolStyle" ,
"createdAt" : 1350918540580 ,
"productId" : "product123" ,
"skuId" : "123"
}
}
My question is: how do I retrieve the value from skuId? I know you can use the notation parent.child in the ‘find’ method in Mongo, but that doesn’t work when reading from the resulting DBObject
This is the code:
val elems = SkuStorage.collection.find(MongoDBObject("i.productId" -> productId))
elems.toSeq.map { element=>
readSkuById(element.get("i.skuId")) //breaks!
}
Do I need to go get(“i”) then parse the string into a JSON? Is there any better way of handling this?
You could try
it returns
Option[String]