查找y为100的数据
db.test_collection.find({y:100})
发现没有,这时候将y为100的数据更新为y为999的数据
db.test_collection.update({y:100},{y:999})
我们再查找y为999的数据
db.test_collection.find({y:999})
发现不存在



我们有时候有这样的需求,在更新一条不存在的数据时,自动创建,这就是update第三个参数,如果为true,表示如果查找的数据不存在,就自动创建一条
db.test_collection.update({y:100},{y:999},true)
这时候再查找y为999的数据,就有了
db.test_collection.find({y:999})

 

 

 

相关文章:

  • 2021-08-08
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2021-06-06
  • 2022-01-31
  • 2022-02-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
  • 2021-07-17
  • 2022-12-23
  • 2021-12-07
相关资源
相似解决方案