I use MongoDB and Spring Data. I typically use repositories to perform CRUD operations. I would like to be able to query a collection, but limit the fields that are returned.
If I have:
I know I can do:Code:public class MyClass { String _id; String lastName; String firstName; ... many more fields ... };
Something like this would return lastName and firstName.Code:db.mycollection.find({lastName: "Jones"},{lastName:1, firstName:1, socialsecurity:0})
How can I duplicate something like this using Spring data.
Can this be done in a repository by annotating a query to exclude certain fields (or include certain fields)? So I would like to use a single domain object, but only populate the fields that are of interest.
Any thoughts?
Thanks,
Tom


Reply With Quote
