Home > Net >  Cannot Update string to Date object in mongodb 4.2
Cannot Update string to Date object in mongodb 4.2

Time:06-30

I have a string field which consists of date, I am trying to run following command mentioned in Update string to Date object in mongodb

db.getCollection('rft').updateMany(
  {},[{ "$set": { "createdate": { "$toDate": "$create_date" } }}]
);

Getting an error: Error: Failed to execute script.

Error: the update operation document must contain atomic operators Details: DBCollection.prototype.updateMany@src/mongo/shell/crud_api.js:625:1 @(shell):1:1

Can someone please help in updating the records to get new field with date time.

CodePudding user response:

Your query seems to work as expected , check playgroud unless something different is expected ...

  • Related