Results 1 to 2 of 2

Thread: MongoDB Restrict Fields Returned in Search (Repository & Template)

  1. #1

    Default 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. #2

    Default

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •