I want to know how to write a Morphia mongodb query with 'or' operator
I wrote mongodb query like this and this work fine
db.Inv.find({$or:[{sug_id:2},{grp_id:2}]})
But i got confused when i try to write this in morphia, following query is wrong but how can write something similar to this
List<Inv> invs = ds.find(Inv.class).field("grp_id").hasAnyOf(grpId).or(field("sug_id")).hasAnyOf(grpId).asList();
Thanks
not sure why hasAnyOf() is in there but try this:
Query<Inv> query = ds.find(Inv.class);
query.or(
query.criteria("grp_id").equal(2),
query.criteria("sug_id").equal(2));
List<Inv> invs = query.asList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With