0

I have seen this, this and a couple of other examples. Some have no solutions and the rest have workarounds.

My question is: As of today (May 2019), is there a way of updating a mongodb field with the value of another field. For example:

//Document example:
{
    _id : '1aa',
    fieldA : 0,
    fieldB : 30,
}

//update command
db.exampleDocument.update(
   { _id: { $in: ['1aa', '2bb', '3cc'] } },
   { $set: { fieldA : $[elem].fieldB } }
)

Where for each document I will get the value of that document's fieldA replaced by the value of that document's fieldB. Is this possible with mongoDB or mongoose, without any looping?

YulePale
  • 6,688
  • 16
  • 46
  • 95

0 Answers0