Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-46484

Mongo shell doesn't allow updateOne operation with a pipeline

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      Robo 3T 1.3 on mac
    • Fully Compatible

      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. 

            Assignee:
            dmitry.agranat@mongodb.com Dmitry Agranat
            Reporter:
            georgy.savva@gmail.com Georgy Savva
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: