我是MongoDB的新手。我试图更新MongoDB中的许多记录。但它把这个错误扔给了我。任何人都可以帮助离开这里吗?
2017-04-13T11:23:07.572-0700 E QUERY [thread1]错误:更新操作文档必须包含原子操作符: DBCollection.prototype.updateMany@src/mongo/shell/crud_api.js:568:1 @(壳):1:1
示例数据:
function back()
{
var i = 0;
var jsArray = @Html.Raw(Json.Serialize(Model));
console.log(jsArray[i].Id;)
}
示例查询:
{
userId: "id#1",
username: "abc",
firstName: "ABC",
lastName: "DEF",
age: 19
}
{
userId: "id#1",
username: "abc",
firstName: "ABC",
lastName: "DEF",
age: 19
}
{
userId: "id#1",
username: "abc",
firstName: "ABC",
lastName: "DEF",
age: 19
}
{
userId: "id#1",
username: "abc",
firstName: "ABC",
lastName: "DEF",
age: 19
}
答案 0 :(得分:0)
updateMany要求您指定要应用的操作。您的示例查询将如下所示:
db.users.updateMany(
{
userId: {
$in: ["id#1","id#2","id#3"]
}
},
{
$set: {
userId: "id#12345",
username: "abc",
firstName: "ABC",
lastName: "DEF",
age: 19
}
})