0

The @Query annotation makes it possible to specify a MongoDB query for a particular method. An example might be @Query("{ 'firstname' : ?0 }"). But what should the parameter to @Query be if I just want to find all documents without specifying a "where" clause? The code below illustrates what I'm trying to achieve but perhaps the question is simply: what is the JSON/BSON query to fetch all documents?

@NoRepositoryBean
public interface QuoteRepository {

    public QuoteProvider findByName(String name);

    public List<QuoteProvider> findAllQuoteProviders();

}

@Repository
public interface MongoQuoteRepository extends QuoteRepository, MongoRepository<QuoteProvider, String> {

    @Query("findAll") // What should this be?
    @Override
    public List<QuoteProvider> findAllQuoteProviders();
}
chrisjleu
  • 4,329
  • 7
  • 42
  • 55

1 Answers1

0

I can't test at the moment, but since it as far as I know has the same query syntax as find(), this should work to get all entries without a condition;

@Query("{}")
Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294