morphia icon indicating copy to clipboard operation
morphia copied to clipboard

MongoDB Morphia elemMatch API

Open Steinkauz opened this issue 11 years ago • 1 comments

Hi,

I posted the question on stackoverflow, but I'm pasting the question here also:

http://stackoverflow.com/questions/30978668/mongodb-morphia-elemmatch-api/30982707?noredirect=1#comment49997944_30982707

I'm trying to put this into morphia query :

db.woot.find({ "bar.tables": { $elemMatch: { "tableId": { $in: [3, 4] }, "tab": { $gte: 20000 } } } })

So I have :

Query q q.field("bar.table").hasThisElement()

And after this I don't know how to finish the query and still using FieldEnd which supports in(), gte() methods without writing whole query myself with BasicDBObjects.

Please help me transform above query to the nicest possible Morphia equivalent.

bar.tables is an array so matching must be done with elemMatch or else it can match first condition from some element and the second condition from the other element, but only elements matching both conditions are valid.

Steinkauz avatar Jun 23 '15 07:06 Steinkauz

My next few days are hectic but I'll try to put something together. I'll answer on SO, though, as the issue tracker here really isn't meant for support questions.

evanchooly avatar Jun 23 '15 12:06 evanchooly