How to get distinct values out of a collection with where condition?
For Example, I have Worker class, which contains status and workerId along with other fields, Here i want to retrieve distinct workerId's which has status="ACTIVE";
I have made enough googling but could not find any solution
Any help would be appreciated
Thanks in advance!
Edit
Sorry guys i didn't put my question properly. I want this to be done using morphia not by using mongodb native query.
Can this be done using MapReduce? Help me out please!
Sorry for the delay in posting,
BasicDBObject dbObject=new BasicDBObject();
dbObject.append("status","ACTIVE");
this dbObject
will act as a where condition,
DBCollection dBCollection = datastore.getCollection(MyEntity.class);
List id=dBCollection.distinct("id",dbObject);
This ID list will contains all distinct ID's whose status="ACTIVE"
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