Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Morphia query with or operator

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

like image 684
user1573690 Avatar asked Jul 26 '13 05:07

user1573690


1 Answers

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();
like image 156
evanchooly Avatar answered Oct 16 '22 21:10

evanchooly