开发者社区 问答 正文

mongodb中 findOneAndUpdate 如何使用:报错

比如数据库有这样的数据{id:'1',count:100}
在使用findOneAndUpdate方法按id=1查询,并对count进行减1操作该怎么写

Document doc= db.getCollection("collection").findOneAndUpdate(new Document("id","1"),new Document());
第二个参数改怎么写?

刚接触mongodb,欢迎大神不吝赐教!

展开
收起
kun坤 2020-06-09 11:18:05 988 分享 版权
1 条回答
写回答
取消 提交回答
  • 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));
    2020-06-09 11:18:11
    赞同 展开评论