MongoDB的update问题(JAVA)——怎么一次更新所有的相同记录
用如下这个函数:
public WriteResult update(DBObject q,
  DBObject o,
  boolean upsert,
  boolean multi)
  throws MongoException
官方API写的是:
upsert - if the database should create the element if it does not exist
multi - if the update should be applied to all objects matching

首先我的collection中有多个相同的document(只是_id不同),但是如何才能一次更新全部的相同document呢


------解决方案--------------------
1)criteria:查询条件,类似于update语句内where后面的内容
2)objNew:update的对象和一些更新的操作符(如$、$inc等),也可以理解为关系型数据库update语句内set后面的内容
3)upsert:如果不存在update的纪录,是否插入objNew这个新的document。true为插入,默认是false,不插入
4)multi:默认是false,只更新找到的第一条纪录,如果为true,按条件查出来的多条纪录全部更新。
------解决方案--------------------
1)upsert:如果不存在update的纪录,是否插入objNew这个新的document。true为插入,默认是false,不插入
2)multi:默认是false,只更新找到的第一条纪录,如果为true,按条件查出来的多条纪录全部更新。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
猜你喜欢
  • 2022-02-16
  • 2021-09-27
  • 2022-12-23
  • 2021-11-01
相关资源
相似解决方案