Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring data mongodb repository. How can I search by a list of IDs?

I have the following class!

public class Task{
    ObjectId id;
    String title;
    String description;

    /* Getters and Setters removed for brevity */
}

and I have the following mongoRepository class, very simple :

public interface TaskRepository extends MongoRepository<Task, String> {

}

As you can see, I have not yet tried to extend this class - What would I want to do here if I want to have a find method, where I could just hand it a list of Ids, and get my list of corresponding tasks back?

like image 613
MickeyThreeSheds Avatar asked May 25 '17 04:05

MickeyThreeSheds


1 Answers

The CrudRepository which MongoRepository extends has a findAll method, which takes an Itereable<ID>

I think that is exactly what you are looking for.

Note that it is renamed to findAllById in the latest Milestone releases.

like image 151
Jens Schauder Avatar answered Oct 12 '22 23:10

Jens Schauder