How to update particular field in mongo db by using MongoRepository Interface?

Anil picture Anil · Aug 16, 2016 · Viewed 15.4k times · Source

How to update a particular field in mongo db collection by using MongoRepository Interface in spring?

Answer

Ravi Mandli picture Ravi Mandli · Jul 7, 2017

I am sure you got the answer by far now, still updating it to help other folks.

you can update specific field by below code.,

 Query query1 = new Query(Criteria.where("id").is("123"));
              Update update1 = new Update();
              update1.set("available", false);
              mongoTemplate.updateFirst(query1, update1, Customer.class);