`
umbrellall1
  • 浏览: 142270 次
  • 性别: Icon_minigender_1
  • 来自: 成都
文章分类
社区版块
存档分类
最新评论

mongeDB 存在数据则更新没有数据则插入

阅读更多
Document doc2 = new Document();
        	doc2.append("$set",doc);
        	collection.updateOne(filter, doc2,new UpdateOptions().upsert(true));

将doc 外层包裹并且设置$set 就可以保留原始数据情况下 新增字段
new UpdateOptions().upsert(true) 默认false  ,true 的情况下有则更新,无则插入原则
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics