MongoDB 3.2.6 未能 运行 updateMany()

MongoDB 3.2.6 failed to run updateMany()

我是 MongoDB 的新手。我试图更新 MongoDB 中的许多记录。但这给了我这个错误。有人可以帮忙吗?

2017-04-13T11:23:07.572-0700 E QUERY [thread1] 错误:更新操作文档必须包含原子运算符: DBCollection.prototype.updateMany@src/mongo/shell/crud_api.js:568:1 @(shell):1:1

示例数据:

{
    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
}

示例查询:

db.users.updateMany(
{
    userId: {
        $in: ["id#1","id#2","id#3"]
    }
},
{
    userId: "id#12345",
    username: "abc",
    firstName: "ABC",
    lastName: "DEF",
    age: 19
})

updateMany 要求您指定要应用的操作。您的示例查询将如下所示:

db.users.updateMany(
{
    userId: {
        $in: ["id#1","id#2","id#3"]
    }
},
{
  $set: {
    userId: "id#12345",
    username: "abc",
    firstName: "ABC",
    lastName: "DEF",
    age: 19
  }
})