Search code examples
mongodbmongodb-queryspring-data-mongodbmongodb-java

Should i use MongoTemplate or DBCollection when query data


[Java Spring] At the moment, I'm using MongoTemplate to query data

  1. MongoTemplate --> return List

    mongoTemplate.find(query, entity)

  2. DbCollection --> return DbCursor

    dbCollection.find()

Then what should i use to best way


Solution

  • since your application is a spring application i would suggest to stick with mongotemplate as it is springframework provided class and can go along well with other spring features. whereas DBcollection is a class from mongo API for java and there might be some cases where you have to play around to get your stuff done.