Reputation: 289
I have 2 columns String id, String Name and long age.
As we would have done in sql - select id FROM USERDETAILS Where Age > 5 would give me arrayList of primary keys that is "Id".
can anyone tell me how to do the same for mongo db using morphia.
I tried with query.retrieveFields(true,"id").get();
but it returns a USERDETAILS Model in return , i need only array of ids. how can i do this please help
Upvotes: 4
Views: 1405
Reputation: 1
use project
Query<Object> query = createQuery(); query.project("fieldNamewhichisalonerequired", true); return query.asList();
Upvotes: 0
Reputation: 6243
You're going to get back your model class with morphia. That's what it does. If you want the raw list of IDs, you'll need to use the driver directly.
Upvotes: 3