index.js
function(data, options, callback) {
            if(_.isFunction(options)) {
                // Set the correct callback function
                callback = options;
                options = {};
            }

            // Create a deferred object for the promise
            var def = Q.defer();

            // If no callback is provided, use a noop function
            callback = callback || function() {};

            // Clear earlier results and options
            _this.result = {};
            _this.options = {};
            _this.sandbox = vm.createContext();

            // Defaulting the options
            _this.options = _.extend(_.clone(DEFAULT_OPTIONS), options);

            if(_this.options.dropCollections === true && _this.options.dropDatabase === true) {
                // Only one of the two flags can be turned on. If both are true, this means the
                // user set the dropCollections itself and this should have higher priority then
                // the default values.
                _this.options.dropDatabase = false;
            }

            if(_this.options.dropDatabase === true) {
                // Make sure to drop the database first
                mongoose.connection.db.dropDatabase(function(err) {
                    if(err) {
                        // Stop seeding if an error occurred
                        return done(err);
                    }

                    // Start seeding when the database is dropped
                    _this._seed(_.cloneDeep(data), done);
                });
            }
            else {
                // Do not drop the entire database, start seeding
                _this._seed(_.cloneDeep(data), done);
            }

            /**
             * This method will be invoked when the seeding is completed or when something
             * went wrong. This method will then call the callback and rejects or resolves
             * the promise object. This way, users of the library can use both.
             *
             * @param  {*}        err    [description]
             * @param  {Object}   result [description]
             */
            function done(err, result) {
                if(err) {
                    def.reject(err);
                    callback(err);
                    return;
                }

                def.resolve(result);
                callback(undefined, result);
            }

            // Return the promise
            return def.promise;
        }
function(data, options, callback) {
            if(_.isFunction(options)) {
                // Set the correct callback function
                callback = options;
                options = {};
            }

            // Create a deferred object for the promise
            var def = Q.defer();

            // If no callback is provided, use a noop function
            callback = callback || function() {};

            // Clear earlier results and options
            _this.result = {};
            _this.options = {};
            _this.sandbox = vm.createContext();

            // Defaulting the options
            _this.options = _.extend(_.clone(DEFAULT_OPTIONS), options);

            if(_this.options.dropCollections === true && _this.options.dropDatabase === true) {
                // Only one of the two flags can be turned on. If both are true, this means the
                // user set the dropCollections itself and this should have higher priority then
                // the default values.
                _this.options.dropDatabase = false;
            }

            if(_this.options.dropDatabase === true) {
                // Make sure to drop the database first
                mongoose.connection.db.dropDatabase(function(err) {
                    if(err) {
                        // Stop seeding if an error occurred
                        return done(err);
                    }

                    // Start seeding when the database is dropped
                    _this._seed(_.cloneDeep(data), done);
                });
            }
            else {
                // Do not drop the entire database, start seeding
                _this._seed(_.cloneDeep(data), done);
            }

            /**
             * This method will be invoked when the seeding is completed or when something
             * went wrong. This method will then call the callback and rejects or resolves
             * the promise object. This way, users of the library can use both.
             *
             * @param  {*}        err    [description]
             * @param  {Object}   result [description]
             */
            function done(err, result) {
                if(err) {
                    def.reject(err);
                    callback(err);
                    return;
                }

                def.resolve(result);
                callback(undefined, result);
            }

            // Return the promise
            return def.promise;
        }
function ( data , options , callback ) { if ( _ . isFunction ( options ) ) { // Set the correct callback function callback = options ; options = { } ; } // Create a deferred object for the promise var def = Q . defer ( ) ; // If no callback is provided, use a noop function callback = callback || function ( ) { } ; // Clear earlier results and options _this . result = { } ; _this . options = { } ; _this . sandbox = vm . createContext ( ) ; // Defaulting the options _this . options = _ . extend ( _ . clone ( DEFAULT_OPTIONS ) , options ) ; if ( _this . options . dropCollections === true && _this . options . dropDatabase === true ) { // Only one of the two flags can be turned on. If both are true, this means the // user set the dropCollections itself and this should have higher priority then // the default values. _this . options . dropDatabase = false ; } if ( _this . options . dropDatabase === true ) { // Make sure to drop the database first mongoose . connection . db . dropDatabase ( function ( err ) { if ( err ) { // Stop seeding if an error occurred return done ( err ) ; } // Start seeding when the database is dropped _this . _seed ( _ . cloneDeep ( data ) , done ) ; } ) ; } else { // Do not drop the entire database, start seeding _this . _seed ( _ . cloneDeep ( data ) , done ) ; } /**
             * This method will be invoked when the seeding is completed or when something
             * went wrong. This method will then call the callback and rejects or resolves
             * the promise object. This way, users of the library can use both.
             *
             * @param  {*}        err    [description]
             * @param  {Object}   result [description]
             */ function done ( err , result ) { if ( err ) { def . reject ( err ) ; callback ( err ) ; return ; } def . resolve ( result ) ; callback ( undefined , result ) ; } // Return the promise return def . promise ; }
Start seeding the database.

@param  {Object}   data     The data object that should be inserted in the database.
@param  {Object}   options  The options object to provide extras.
@param  {Function} callback The method that should be called when the seeding is done.
Start seeding the database .