index.js
function(data, done) {
            try {
                // Retrieve all the dependencies
                _.forEach(data._dependencies || {}, function(value, key) {
                    if(this.sandbox[key] !== undefined) {
                        // Do nothing if the dependency is already defined
                        return;
                    }

                    this.sandbox[key] = module.parent.require(value);
                }.bind(this));

                // Remove the dependencies property
                delete data._dependencies;
            }
            catch(e) {
                // Stop execution and return the MODULE_NOT_FOUND error
                return done(e);
            }

            // Iterate over all the data objects
            async.eachSeries(Object.keys(data), function(key, next) {
                _this.result[key] = {};

                var value = data[key];

                try {
                    if(!value._model) {
                        // Throw an error if the model could not be found
                        throw new Error('Please provide a _model property that describes which database model should be used.');
                    }

                    var modelName = value._model;

                    // Remove model and unique properties
                    delete value._model;

                    // retrieve the model depending on the name provided
                    var Model = mongoose.model(modelName);

                    async.series([
                        function(callback) {
                            if(_this.options.dropCollections === true) {
                                // Drop the collection
                                mongoose.connection.db.dropCollection(Model.collection.name, function(err) {
                                    callback();
                                });
                            }
                            else {
                                callback();
                            }
                        },
                        function(callback) {
                            async.eachSeries(Object.keys(value), function(k, innerNext) {
                                var modelData = value[k],
                                    data = _this._unwind(modelData);

                                // Create the model
                                Model.create(data, function(err, result) {
                                    if(err) {
                                        // Do not stop execution if an error occurs
                                        return innerNext(err);
                                    }

                                    _this.result[key][k] = result;

                                    innerNext();
                                });
                            }, callback);
                        }
                    ], next);
                }
                catch(err) {
                    // If the model does not exist, stop the execution
                    return next(err);
                }
            }, function(err) {
                if(err) {
                    // Make sure to not return the result
                    return done(err);
                }

                done(undefined, _this.result);
            });
        }
function(data, done) {
            try {
                // Retrieve all the dependencies
                _.forEach(data._dependencies || {}, function(value, key) {
                    if(this.sandbox[key] !== undefined) {
                        // Do nothing if the dependency is already defined
                        return;
                    }

                    this.sandbox[key] = module.parent.require(value);
                }.bind(this));

                // Remove the dependencies property
                delete data._dependencies;
            }
            catch(e) {
                // Stop execution and return the MODULE_NOT_FOUND error
                return done(e);
            }

            // Iterate over all the data objects
            async.eachSeries(Object.keys(data), function(key, next) {
                _this.result[key] = {};

                var value = data[key];

                try {
                    if(!value._model) {
                        // Throw an error if the model could not be found
                        throw new Error('Please provide a _model property that describes which database model should be used.');
                    }

                    var modelName = value._model;

                    // Remove model and unique properties
                    delete value._model;

                    // retrieve the model depending on the name provided
                    var Model = mongoose.model(modelName);

                    async.series([
                        function(callback) {
                            if(_this.options.dropCollections === true) {
                                // Drop the collection
                                mongoose.connection.db.dropCollection(Model.collection.name, function(err) {
                                    callback();
                                });
                            }
                            else {
                                callback();
                            }
                        },
                        function(callback) {
                            async.eachSeries(Object.keys(value), function(k, innerNext) {
                                var modelData = value[k],
                                    data = _this._unwind(modelData);

                                // Create the model
                                Model.create(data, function(err, result) {
                                    if(err) {
                                        // Do not stop execution if an error occurs
                                        return innerNext(err);
                                    }

                                    _this.result[key][k] = result;

                                    innerNext();
                                });
                            }, callback);
                        }
                    ], next);
                }
                catch(err) {
                    // If the model does not exist, stop the execution
                    return next(err);
                }
            }, function(err) {
                if(err) {
                    // Make sure to not return the result
                    return done(err);
                }

                done(undefined, _this.result);
            });
        }
function ( data , done ) { try { // Retrieve all the dependencies _ . forEach ( data . _dependencies || { } , function ( value , key ) { if ( this . sandbox [ key ] !== undefined ) { // Do nothing if the dependency is already defined return ; } this . sandbox [ key ] = module . parent . require ( value ) ; } . bind ( this ) ) ; // Remove the dependencies property delete data . _dependencies ; } catch ( e ) { // Stop execution and return the MODULE_NOT_FOUND error return done ( e ) ; } // Iterate over all the data objects async . eachSeries ( Object . keys ( data ) , function ( key , next ) { _this . result [ key ] = { } ; var value = data [ key ] ; try { if ( ! value . _model ) { // Throw an error if the model could not be found throw new Error ( 'Please provide a _model property that describes which database model should be used.' ) ; } var modelName = value . _model ; // Remove model and unique properties delete value . _model ; // retrieve the model depending on the name provided var Model = mongoose . model ( modelName ) ; async . series ( [ function ( callback ) { if ( _this . options . dropCollections === true ) { // Drop the collection mongoose . connection . db . dropCollection ( Model . collection . name , function ( err ) { callback ( ) ; } ) ; } else { callback ( ) ; } } , function ( callback ) { async . eachSeries ( Object . keys ( value ) , function ( k , innerNext ) { var modelData = value [ k ] , data = _this . _unwind ( modelData ) ; // Create the model Model . create ( data , function ( err , result ) { if ( err ) { // Do not stop execution if an error occurs return innerNext ( err ) ; } _this . result [ key ] [ k ] = result ; innerNext ( ) ; } ) ; } , callback ) ; } ] , next ) ; } catch ( err ) { // If the model does not exist, stop the execution return next ( err ) ; } } , function ( err ) { if ( err ) { // Make sure to not return the result return done ( err ) ; } done ( undefined , _this . result ) ; } ) ; }
The internal method for seeding the database.

@param  {Object}   data The data that should be seeded.
@param  {Function} done The method that should be called when the seeding is done
The internal method for seeding the database .