如何使用MongoRepository接口更新mongo数据库中的特定字段? [英] How to update particular field in mongo db by using MongoRepository Interface?

查看:756
本文介绍了如何使用MongoRepository接口更新mongo数据库中的特定字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在春季使用MongoRepository接口更新mongo db集合中的特定字段?

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

推荐答案

我敢肯定,您到目前为止已经知道答案了,仍会对其进行更新以帮助其他人.

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);

这篇关于如何使用MongoRepository接口更新mongo数据库中的特定字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆