Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting only one column in mongo db using morphia

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

like image 561
Ekata Avatar asked Sep 15 '25 06:09

Ekata


1 Answers

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.

like image 88
evanchooly Avatar answered Sep 18 '25 09:09

evanchooly