Tuesday, 2 May 2017

How to update count of a field depending on another field using $addFields

I have a field called pin_count which has a count of another field called pins but due to broken logic the count of both fields mismatched, so I am writing migration script using migrate-mongo and below is what I did. But not sure why it's not working.

return BPromise.resolve(types).mapSeries(col => {
      const collection = db.collection(col);

      return collection.aggregate([
          { '$addFields': {
              'pin_count': { '$size': '$pins'}
          }},
          { "$out": col }
      ]);
  });



via Krapali

No comments:

Post a Comment