How to use the bson.Code function in bson

To help you get started, we’ve selected a few bson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hyperstudio / MIT-Annotation-Data-Store / node_modules / mongoose / node_modules / mongodb / lib / mongodb / collection.js View on Github external
} 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);
    });
  }
};
github Hanul / UPPERCASE / UPPERCASE-DB / node_modules / mongodb / lib / mongodb / collection / aggregation.js View on Github external
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 {
github RTimal / DrawingBoard / node_modules / mongoose / node_modules / mongodb / lib / mongodb / collection.js View on Github external
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];
github andreirtaylor / BoardGameTracking / node_modules / mongodb / lib / mongodb / collection / aggregation.js View on Github external
});
  } 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);
    });
  }
};
github Adobe-CEP / Samples / CEP_HTML_Test_Extension / node_modules / mongodb / lib / mongodb / collection.js View on Github external
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;
}
github CodeArtemis / TriggerRally / server / node_modules / mongodb / lib / mongodb / collection.js View on Github external
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;
}
github YoavGivati / salmon / node / node_modules / mongodb / lib / mongodb / collection / aggregation.js View on Github external
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;
}
github howarddierking / RestBugs / RestBugs-Node / node_modules / mongojs / node_modules / mongodb / lib / mongodb / collection.js View on Github external
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;
}
github Hanul / UPPERCASE / UPPERCASE-DB / node_modules / mongodb / lib / mongodb / collection / aggregation.js View on Github external
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;
}
github cwbuecheler / node-tutorial-for-frontend-devs / node_modules / mongodb / lib / mongodb / collection.js View on Github external
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;
}