fiware-sth-comet icon indicating copy to clipboard operation
fiware-sth-comet copied to clipboard

Prepopulate and feed aggregate data collections in 1 update (upsert) operation when MongoDB supports it

Open gtorodelvalle opened this issue 9 years ago • 0 comments

Currently the MongoDB $ positional update operator cannot be combined with upserts (see http://docs.mongodb.org/manual/reference/operator/update/positional/#upsert).

This issue is known and currently under study: https://jira.mongodb.org/browse/SERVER-3326 Once the issue is solved, it will be possible to prepopulate collections or update their docs using just one update operation like this:

  collection.update(
    // Returning all the update operators currently returned by getAggregateUpdate4Insert
    //  and getAggregateUpdate4Update in the same object
    getAggregateUpdateCondition(entityId, entityType, attrName, resolution, recvTime),
    getAggregateUpdate(attrValue),
    {
      upsert: true,
      writeConcern: {
        w: !isNaN(sthConfig.WRITE_CONCERN) ? parseInt(sthConfig.WRITE_CONCERN) : sthConfig.WRITE_CONCERN
      }
    },
    function (err) {
      callback(err);
    }
  );

gtorodelvalle avatar May 22 '15 11:05 gtorodelvalle