假如集合中有如下数据

{ "_id" : ObjectId("4b97e62bf1d8c7152c9ccb74"), "title" : "ABC",
  "comments" : [ { "by" : "joe", "votes" : 3 }, { "by" : "jane", "votes" : 7 } ] }

将comments值中所有votes的值改为1

 t.update( obj, {$set:{'comments.$.votes':1}}, false, true )

结果为:

{ "_id" : ObjectId("4b97e62bf1d8c7152c9ccb74"), "title" : "ABC",
  "comments" : [ { "by" : "joe", "votes" : 1 }, { "by" : "jane", "votes" : 1 } ] }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-28
  • 2022-12-23
猜你喜欢
  • 2021-12-27
  • 2021-11-21
  • 2022-01-19
  • 2022-12-23
  • 2021-12-21
  • 2021-09-01
相关资源
相似解决方案