Info
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.
Top User Comments
dmitry.agranat commented on Tue, 3 Mar 2020 17:30:50 +0000:
georgy.savva@gmail.com since this works as expected with mongo shell 4.2, I will go ahead and close this ticket. For issues related to Robo 3T, please contact Robo support.
georgy.savva@gmail.com commented on Mon, 2 Mar 2020 09:26:06 +0000:
Sorry for misleading you, I forgot to mention that this happening only in Robo 3T GUI.
So yes. It works as expected in mongo shell 4.2. Error persists only in Robo 3T.
dmitry.agranat commented on Sun, 1 Mar 2020 21:25:19 +0000:
Hi georgy.savva@gmail.com, could you please clarify if this works as expected when you use mongo shell 4.2?