Announcement Announcement Module
Collapse
No announcement yet.
MongoDB Restrict Fields Returned in Search (Repository & Template) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MongoDB Restrict Fields Returned in Search (Repository & Template)

    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:

    Code:
    public class MyClass {
        String _id;
        String lastName;
        String firstName;
        ... many more fields ...
    };
    I know I can do:

    Code:
    db.mycollection.find({lastName: "Jones"},{lastName:1, firstName:1, socialsecurity:0})
    Something like this would return lastName and firstName.

    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

  • #2
    Found the answer. It was in the documentation, but wasn't found with the search I was using.

    Comment

    Working...
    X