Unable to use update pipeline with findOneAndUpdate

Hello,

I am not able use update pipeline with findOneAndUpdate and need help with the same.

db.getCollection('test').findOneAndUpdate({ lastAssignedTime: {$lt: new Date((new Date())-1000*10)} },
 [
  {
      $set: 
      {
            priority: 
            {
                "$cond": 
                {
                    if: {$gte: ["$vmAssignedSessions", 3]},
                    then: 99,
                    else: 1,
                }
            }
      }
  }
 ],
 {sort: { "priority" : 1 }}
)

I keep running into

021-03-03T17:24:11.474-0800 E QUERY [js] Error: the update operation document must contain atomic operators :
DBCollection.prototype.findOneAndUpdate@src/mongo/shell/crud_api.js:819:1

Mongo component versions:
MongoDB shell version v4.0.0

connecting to: mongodb://127.0.0.1:27017

MongoDB server version: 4.2.12

Thanks in advance!

Hello @Abhishek_Kumar_Singh,

aggregation pipeline is support from mongodb v4.2, i can see your server version is valid but You have to update your mongodb shell version to 4.2 or above.

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.