How to rewrite mapReduce using aggregate or anyother alternative

209 views Asked by At

Hi I am facing difficulty in rewriting mapReduce as it is not supported in aws documentdb any workaround will be appreciated

var historyMap = function () {
            var values = {
                updateType: this.updateType.name + '(v.' + this.version + ')',
                version: this.version,
                revisionTimestamp: this.revisionTimestamp,
                entityId: this.entityId
            };
            emit(this.entityId, values);
        };
        var scenarioMap = function () {
            emit(this._id, {friendlyId: this.friendlyId});
        };
        var reduce = function (key, values) {
            var updateTypes = '';
            var friendlyId = '';
            if (values[0].revisionTimestamp !== 'undefined') {
                var revisionTimestamp = values[values.length - 1].revisionTimestamp;
            }
            values.forEach(function (value) {
                if (value.updateType) {
                    updateTypes += value.updateType + ',';
                }
                if (value.friendlyId) {
                    friendlyId = value.friendlyId;
                }
            });
            return {updateType: updateTypes, entityId: key, friendlyId: friendlyId, revisionTimestamp: revisionTimestamp};
        };

HistoryReport.find({}).remove().exec().then(function () {
        History.mapReduce({
            map: historyMap,
            reduce: reduce,
            query: {type: 'Scenario', revisionTimestamp: {$gte: startDate, $lt: endDate}},
            out: {'reduce': historyReportCollectionName},
            sort: {revisionTimestamp: -1}
        }, function () {
            Scenario.mapReduce({
                map: scenarioMap,
                reduce: reduce,
                out: {'reduce': historyReportCollectionName}
            }, function () {
                HistoryReport.find({'value.updateType': {'$exists': true}}).exec().then(function (data) {
                    populateSheet(data);
                });
            });
        });
    }).then(null, function (err) {
        next(new errorHandler.error.ProcessingError(errorHandler.getErrorMessage(err)));
    });

I am getting the following error MongoError {name: "MongoError", message: "Feature not supported: mapreduce", ok: 0, errmsg: "Feature not supported: mapreduce", code: 303, …}code: 303errmsg: "Feature not supported: mapreduce"message: "Feature not supported: mapreduce"name: "MongoError"ok: 0

0

There are 0 answers