java 如何使用 MongoRepository 接口更新 mongo db 中的特定字段?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38973231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 03:59:10 来源:igfitidea点击:
How to update particular field in mongo db by using MongoRepository Interface?
提问by Anil
How to update a particular field in mongo db collection by using MongoRepository Interface in spring?
如何在 spring 中使用 MongoRepository 接口更新 mongo db 集合中的特定字段?
回答by Ravi Mandli
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);