Setting field2=field1 in MongoDB

I am unable to update my document when I run
db.xx.updateOne({_id: ObjectId(""}, {$set: {lq: uq}) I get the error uncaught exception: ReferenceError: uq is not defined

uq field exists and contains integers, not sure why it don’t work. Please help.

>Solution :

db.collection.update({
  "_id": ObjectId("5a934e000102030405000000")
},
[
  {
    "$set": {
      "field1": "$field2"
    }
  }
])

mongoplayground

Leave a Reply