Spring data mongodb remove a property from a document using MongoTemplate Spring data mongodb remove a property from a document using MongoTemplate mongodb mongodb

Spring data mongodb remove a property from a document using MongoTemplate


The following example removes the property activationToken from documents with the email xxx.xxx@xxx.com using the $unset update modifier:

Query query = new Query();query.addCriteria(Criteria.where("email").is("xxx.xxx@xxx.com"));Update update = new Update();update.unset("activationToken");// run update operationmongoTemplate.updateMulti(query, update, User.class);