How to update a particular field in mongo db collection by using MongoRepository Interface in spring?
As of today, you can't update the document using MongoRepository
using one query. If you really want to update a particular field using MongoRepository
then following is the steps:
Example:
MyDocument myDocumentToUpdate = myDocumentRepository.findById(documentId); // fetching a document that you want to update the field
myDocumentToUpdate.setMyField(myNewValue); // setting the new value to the field myField
myDocumentRepository.save(myDocumentToUpdate); // saving (It basically updates the document) the updated document