src/back/MongoAdapter.js
function insertObject(entityObject) {
  var mongoAdapter = this;

  expect(arguments).to.have.length(
    1,
    'Invalid arguments length when inserting an object in a MongoAdapter ' +
    '(it has to be passed 1 argument)'
  );

  return new Promise(function (resolve, reject) {
    expect(entityObject).to.be.an.instanceOf(
      Entity,
      'Invalid argument "entityObject" when inserting an object in a ' +
      'MongoAdapter (it has to be an Entity instance)'
    );

    var EntityClass = entityObject.Entity;

    mongoAdapter
      .getDatabase()
      .then(function (database) {
        return database
          .collection(getEntityCollectionName(EntityClass))
          .insertOne(
            objectToDocument(entityObject)
          );
      })
      .then(function (result) {
        expect(result.insertedCount).to.equal(
          1,
          'Invalid result.insertedCount return of collection.insertOne ' +
          'in MongoDB driver when inserting an Object (it should be 1)'
        );

        resolve();
      })
      .catch(reject);
  });
}
function insertObject(entityObject) {
  var mongoAdapter = this;

  expect(arguments).to.have.length(
    1,
    'Invalid arguments length when inserting an object in a MongoAdapter ' +
    '(it has to be passed 1 argument)'
  );

  return new Promise(function (resolve, reject) {
    expect(entityObject).to.be.an.instanceOf(
      Entity,
      'Invalid argument "entityObject" when inserting an object in a ' +
      'MongoAdapter (it has to be an Entity instance)'
    );

    var EntityClass = entityObject.Entity;

    mongoAdapter
      .getDatabase()
      .then(function (database) {
        return database
          .collection(getEntityCollectionName(EntityClass))
          .insertOne(
            objectToDocument(entityObject)
          );
      })
      .then(function (result) {
        expect(result.insertedCount).to.equal(
          1,
          'Invalid result.insertedCount return of collection.insertOne ' +
          'in MongoDB driver when inserting an Object (it should be 1)'
        );

        resolve();
      })
      .catch(reject);
  });
}
function insertObject ( entityObject ) { var mongoAdapter = this ; expect ( arguments ) . to . have . length ( 1 , 'Invalid arguments length when inserting an object in a MongoAdapter ' + '(it has to be passed 1 argument)' ) ; return new Promise ( function ( resolve , reject ) { expect ( entityObject ) . to . be . an . instanceOf ( Entity , 'Invalid argument "entityObject" when inserting an object in a ' + 'MongoAdapter (it has to be an Entity instance)' ) ; var EntityClass = entityObject . Entity ; mongoAdapter . getDatabase ( ) . then ( function ( database ) { return database . collection ( getEntityCollectionName ( EntityClass ) ) . insertOne ( objectToDocument ( entityObject ) ) ; } ) . then ( function ( result ) { expect ( result . insertedCount ) . to . equal ( 1 , 'Invalid result.insertedCount return of collection.insertOne ' + 'in MongoDB driver when inserting an Object (it should be 1)' ) ; resolve ( ) ; } ) . catch ( reject ) ; } ) ; }
Saves an Entity instance, inserting on DB.
@name module:back4app-entity-mongodb.MongoAdapter#insertObject
@function
@param {!module:module:back4app-entity/models/Entity} entityObject
Entity instance being saved, to insert on DB.
@returns {Promise.<undefined|Error>} Promise that returns nothing if succeed
and the Error if failed.
@example
entity.adapter.insertObject(entity)
.then(function () {
entity.isNew = false;
entity.clean();
});
Saves an Entity instance inserting on DB .