0

I have collection where documents have field as an array. I need to rename one field inside each item of this array, but in mongodb all variants looks very monstrous. I even try to use $[] but I can't refer to old value of object, only custom:

collection.update(
{ customField: { $exists: true } },
{
  $set:
      {
        'payload.oneMoreField.$[].path': 'howReferToOldValue',
      },
  $unset:
      {
        'payload.oneMoreField.$[].way': '',
      },
},
  options
);

Somebody knows an easy way to just change the value of a key in monogodb ?

  • Possible duplicate of [How can I rename a field for all documents in MongoDB?](https://stackoverflow.com/questions/9254351/how-can-i-rename-a-field-for-all-documents-in-mongodb) – roottraveller Jul 28 '18 at 17:49
  • @roottraveller, unfortunetly not, I need simple way to rename fields in array field – Max Mabius Jul 29 '18 at 14:23

0 Answers0