Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring data mongodb , use MongoRepository or MongoTemplate?

If use MongoRepository, You can have following code:

@Repository
public interface UserRepo extends MongoRepository<User, String> {

    // additional methods go here 

} 

then you do userRepo.save() find() etc to do CRUD ops.

or you just MongoTemplate and do CRUD ops.

My question is which is preferred? what are the pros and cons for each approach? Thanks!

like image 710
Bobo Avatar asked Sep 15 '25 22:09

Bobo


1 Answers

ok, by looking at source code MongoRepository consume mongoTemplate and provide a set of common DAO API so in other words, use MongoRepository is preferred way.

like image 185
Bobo Avatar answered Sep 18 '25 17:09

Bobo