Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} else {
// Create execution scope
var scope = reduce != null && reduce instanceof Code
? reduce.scope
: {};
scope.ns = this.collectionName;
scope.keys = keys;
scope.condition = condition;
scope.initial = initial;
// Pass in the function text to execute within mongodb.
var groupfn = groupFunction.replace(/ reduce;/, reduce.toString() + ';');
this.db.eval(new Code(groupfn, scope), function (err, results) {
if (err) return callback(err, null);
callback(null, results.result || results);
});
}
};
group: {
'ns': this.collectionName
, '$reduce': reduceFunction
, 'cond': condition
, 'initial': initial
, 'out': "inline"
}
};
// if finalize is defined
if(finalize != null) selector.group['finalize'] = finalize;
// Set up group selector
if ('function' === typeof keys || keys instanceof Code) {
selector.group.$keyf = keys instanceof Code
? keys
: new Code(keys);
} else {
var hash = {};
keys.forEach(function (key) {
hash[key] = 1;
});
selector.group.key = hash;
}
// Set read preference if we set one
var readPreference = shared._getReadConcern(this, options);
// Execute command
this.db.command(selector, {readPreference: readPreference}, function(err, result) {
if(err) return callback(err, null);
callback(null, result.retval);
});
} else {
group: {
'ns': this.collectionName
, '$reduce': reduceFunction
, 'cond': condition
, 'initial': initial
, 'out': "inline"
}
};
// if finalize is defined
if(finalize != null) selector.group['finalize'] = finalize;
// Set up group selector
if ('function' === typeof keys || keys instanceof Code) {
selector.group.$keyf = keys instanceof Code
? keys
: new Code(keys);
} else {
var hash = {};
keys.forEach(function (key) {
hash[key] = 1;
});
selector.group.key = hash;
}
var cmd = DbCommand.createDbSlaveOkCommand(this.db, selector);
// Set read preference if we set one
var readPreference = options['readPreference'] ? options['readPreference'] : false;
this.db._executeQueryCommand(cmd, {read:readPreference}, function (err, result) {
if(err != null) return callback(err);
var document = result.documents[0];
});
} else {
// Create execution scope
var scope = reduce != null && reduce instanceof Code
? reduce.scope
: {};
scope.ns = this.collectionName;
scope.keys = keys;
scope.condition = condition;
scope.initial = initial;
// Pass in the function text to execute within mongodb.
var groupfn = groupFunction.replace(/ reduce;/, reduce.toString() + ';');
this.db.eval(new Code(groupfn, scope), function (err, results) {
if (err) return callback(err, null);
callback(null, results.result || results);
});
}
};
function processScope (scope) {
if (!utils.isObject(scope)) {
return scope;
}
var keys = Object.keys(scope);
var i = keys.length;
var key;
while (i--) {
key = keys[i];
if ('function' == typeof scope[key]) {
scope[key] = new Code(String(scope[key]));
}
}
return scope;
}
function processScope (scope) {
if (!utils.isObject(scope)) {
return scope;
}
var keys = Object.keys(scope);
var i = keys.length;
var key;
while (i--) {
key = keys[i];
if ('function' == typeof scope[key]) {
scope[key] = new Code(String(scope[key]));
}
}
return scope;
}
function processScope (scope) {
if (!utils.isObject(scope)) {
return scope;
}
var keys = Object.keys(scope);
var i = keys.length;
var key;
var new_scope = {};
while (i--) {
key = keys[i];
if ('function' == typeof scope[key]) {
new_scope[key] = new Code(String(scope[key]));
} else {
new_scope[key] = processScope(scope[key]);
}
}
return new_scope;
}
function processScope (scope) {
if (!utils.isObject(scope)) {
return scope;
}
var keys = Object.keys(scope);
var i = keys.length;
var key;
while (i--) {
key = keys[i];
if ('function' == typeof scope[key]) {
scope[key] = new Code(String(scope[key]));
}
}
return scope;
}
function processScope (scope) {
if (!utils.isObject(scope)) {
return scope;
}
var keys = Object.keys(scope);
var i = keys.length;
var key;
var new_scope = {};
while (i--) {
key = keys[i];
if ('function' == typeof scope[key]) {
new_scope[key] = new Code(String(scope[key]));
} else {
new_scope[key] = processScope(scope[key]);
}
}
return new_scope;
}
function processScope (scope) {
if (!utils.isObject(scope)) {
return scope;
}
var keys = Object.keys(scope);
var i = keys.length;
var key;
while (i--) {
key = keys[i];
if ('function' == typeof scope[key]) {
scope[key] = new Code(String(scope[key]));
}
}
return scope;
}