Friday, 6 September 2013

Query for specific subdocuments in MongoDB/Morphia

Query for specific subdocuments in MongoDB/Morphia

I have a document stored in MongoDB that looks something like this:
{ '_id' : 'XXX', 'myProps' : [ { '_id' : 'YYY', 'propA' : 'ValueA' }, {
'_id' : 'ZZZ', 'propA' : 'ValueB' } ] }
I'm using Morphia to model this into Java objects. What I would like to do
is query for elements within myProps that have a propA value of 'ValueA'.
Is this possible? Is it possible to query for specific values within a
subdocument? I've tried using queries like:
myProps.propA == 'ValueA'
...but, I still see all values of myProps being returned. Is there
something I'm missing in my query? Or is it not possible to make such a
query using Morphia/MongoDB?

No comments:

Post a Comment