src/back/MongoAdapter.js
function findObjects(EntityClass, query, params) {
  expect(arguments).to.have.length.within(
    2,
    3,
    'Invalid arguments length when inserting an object in a MongoAdapter ' +
    '(it has to be passed 2 or 3 arguments)'
  );

  function findDocuments(db) {
    // cleaning params
    params = params || {};
    params.sort = params.sort || {id: 1};
    params.skip = params.skip || 0;
    params.limit = params.limit || 0;

    if (params.sort.hasOwnProperty('id')) {
      params.sort._id = params.sort.id;
      delete params.sort.id;
    }

    return _buildCursor(db, EntityClass, query, params)
        .skip(params.skip)
        .limit(params.limit)
        .sort(params.sort)
        .toArray();
  }

  function populateEntities(docs) {
    var entities = [];
    for (var i = 0; i < docs.length; i++) {
      entities.push(documentToObject(docs[i], EntityClass.adapterName));
    }
    return entities;
  }

  return this.getDatabase()
    .then(findDocuments)
    .then(populateEntities);
}
function findObjects(EntityClass, query, params) {
  expect(arguments).to.have.length.within(
    2,
    3,
    'Invalid arguments length when inserting an object in a MongoAdapter ' +
    '(it has to be passed 2 or 3 arguments)'
  );

  function findDocuments(db) {
    // cleaning params
    params = params || {};
    params.sort = params.sort || {id: 1};
    params.skip = params.skip || 0;
    params.limit = params.limit || 0;

    if (params.sort.hasOwnProperty('id')) {
      params.sort._id = params.sort.id;
      delete params.sort.id;
    }

    return _buildCursor(db, EntityClass, query, params)
        .skip(params.skip)
        .limit(params.limit)
        .sort(params.sort)
        .toArray();
  }

  function populateEntities(docs) {
    var entities = [];
    for (var i = 0; i < docs.length; i++) {
      entities.push(documentToObject(docs[i], EntityClass.adapterName));
    }
    return entities;
  }

  return this.getDatabase()
    .then(findDocuments)
    .then(populateEntities);
}
function findObjects ( EntityClass , query , params ) { expect ( arguments ) . to . have . length . within ( 2 , 3 , 'Invalid arguments length when inserting an object in a MongoAdapter ' + '(it has to be passed 2 or 3 arguments)' ) ; function findDocuments ( db ) { // cleaning params params = params || { } ; params . sort = params . sort || { id : 1 } ; params . skip = params . skip || 0 ; params . limit = params . limit || 0 ; if ( params . sort . hasOwnProperty ( 'id' ) ) { params . sort . _id = params . sort . id ; delete params . sort . id ; } return _buildCursor ( db , EntityClass , query , params ) . skip ( params . skip ) . limit ( params . limit ) . sort ( params . sort ) . toArray ( ) ; } function populateEntities ( docs ) { var entities = [ ] ; for ( var i = 0 ; i < docs . length ; i ++ ) { entities . push ( documentToObject ( docs [ i ] , EntityClass . adapterName ) ) ; } return entities ; } return this . getDatabase ( ) . then ( findDocuments ) . then ( populateEntities ) ; }
Find objects in the database matching given query.
@name module:back4app-entity-mongodb.MongoAdapter#findObjects
@function
@param {!module:back4app-entity/models.Entity} entityObject The Entity Class
which instance will be searched within the collections.
@param {?Object} query Object for query search.
@param {?Object} param Object for pagination parameters.
@returns {Promise.<object|Error>} Promise that returns found objects if
succeed or Error if failed.
@example
mongoAdapter.findObjects(Car, {year: 1990})
.then(function(cars) {
for (var i = 0; i < cars.length; i++) {
var car = cars[i];
console.log(car);
}
});
Find objects in the database matching given query .