|
Hi. I am trying to execute quires from the documentation on my local Mongodb replica set with database version 4.2
https://docs.mongodb.com/manual/reference/method/db.collection.updateOne/#example-2
db.students3.updateOne(
|
{ _id: 3 },
|
[
|
{ $set: { average: { $trunc: [ { $avg: "$tests" }, 0 ] }, lastUpdate: "$$NOW" } },
|
{ $set: { grade: { $switch: {
|
branches: [
|
{ case: { $gte: [ "$average", 90 ] }, then: "A" },
|
{ case: { $gte: [ "$average", 80 ] }, then: "B" },
|
{ case: { $gte: [ "$average", 70 ] }, then: "C" },
|
{ case: { $gte: [ "$average", 60 ] }, then: "D" }
|
],
|
default: "F"
|
} } } }
|
]
|
)
|
I get that error (You can see on the screenshoot):
Failed to execute script. Error: the update operation document must contain atomic operators Details: DBCollection.prototype.updateOne@src/mongo/shell/crud_api.js:542:1 @(shell):1:1
|
But when I execute this query in the mongo CLI or in the console on the documentation site - everything is fine.
|