比如数据库有这样的数据{id:'1',count:100}
在使用findOneAndUpdate方法按id=1查询,并对count进行减1操作该怎么写
Document doc= db.getCollection("collection").findOneAndUpdate(new Document("id","1"),new Document()); 第二个参数改怎么写?
刚接触mongodb,欢迎大神不吝赐教!
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
getCollection(collectionName).findOneAndUpdate(new Document("_id", 6), new Document("$inc", CollectionUtil.arrayAsMap("count", -1)))######人呢??
###### Document old=new Document("xx", ""); old.append("xx.key", "xxvalue"); Document new1=new Document(); new1.append("child_list", JSONObject.toJSON(new object("xx","count-1","xx"))); collection.findOneAndUpdate( old, new Document().append("$set", new1));