我努力更新同一集合的多个文档,这些文档需要将字段添加到 JSON“根”,以及一个名为logs的现有数组的新对象。
我正在尝试这个
db.getCollection('charges').
update({'supports.dest':ObjectId("xyz"),
date:{
$gte: new Date(2017, 11),
$lt: new Date(2017, 12)
},
"status": {$nin : ["Captured"]
}
},
{$set: {"status": "BillingSuspended",
"replacedStatus":"Captured"}
},
{multi:true},
{$push :
{logs : {"replacedStatus" : "Captured" ,
date: new Date ('2017-12-13T22:00:00.000Z')
}
}
}
)
Run Code Online (Sandbox Code Playgroud)
我在下面收到这个错误,我尝试取出 multi:true 但后来我失去了允许我同时更新许多文档的 multi 属性。我想要一个在 Robomongo 上运行的查询。如果你能帮助我,我将不胜感激。
错误:
[Failed to execute script.
Error: Fourth argument must be empty when specifying upsert and multi with an object. :
DBCollection.prototype._parseUpdate@src/mongo/shell/collection.js:522:1
DBCollection.prototype.update@src/mongo/shell/collection.js:552:18
@(shell):1:1]
Run Code Online (Sandbox Code Playgroud)