lib/plugin.js
function deepPopulatePlugin(schema, defaultOptions) {
    schema._defaultDeepPopulateOptions = defaultOptions = defaultOptions || {}

    /**
     * Populates this document with the specified paths.
     * @param paths the paths to be populated.
     * @param options (optional) the population options.
     * @param cb (optional) the callback.
     * @return {MongoosePromise}
     */
    schema.methods.deepPopulate = function (paths, options, cb) {
      return deepPopulate(this.constructor, this, paths, options, cb)
    }

    /**
     * Populates provided documents with the specified paths.
     * @param docs the documents to be populated.
     * @param paths the paths to be populated.
     * @param options (optional) the population options.
     * @param cb (optional) the callback.
     * @return {MongoosePromise}
     */
    schema.statics.deepPopulate = function (docs, paths, options, cb) {
      return deepPopulate(this, docs, paths, options, cb)
    }

    function deepPopulate(model, docs, paths, options, cb) {
      if (isFunction(options)) {
        cb = options
        options = null
      }
      else {
        cb = cb || noop
      }

      return createMongoosePromise(function (resolve, reject) {
        if (docs == null || docs.length === 0) {
          return resolve(docs), cb(null, docs)
        }

        execute(model, docs, paths, options, defaultOptions, false, function (err, docs) {
          if (err) reject(err), cb(err)
          else resolve(docs), cb(null, docs)
        })
      })
    }
  }
function deepPopulatePlugin(schema, defaultOptions) {
    schema._defaultDeepPopulateOptions = defaultOptions = defaultOptions || {}

    /**
     * Populates this document with the specified paths.
     * @param paths the paths to be populated.
     * @param options (optional) the population options.
     * @param cb (optional) the callback.
     * @return {MongoosePromise}
     */
    schema.methods.deepPopulate = function (paths, options, cb) {
      return deepPopulate(this.constructor, this, paths, options, cb)
    }

    /**
     * Populates provided documents with the specified paths.
     * @param docs the documents to be populated.
     * @param paths the paths to be populated.
     * @param options (optional) the population options.
     * @param cb (optional) the callback.
     * @return {MongoosePromise}
     */
    schema.statics.deepPopulate = function (docs, paths, options, cb) {
      return deepPopulate(this, docs, paths, options, cb)
    }

    function deepPopulate(model, docs, paths, options, cb) {
      if (isFunction(options)) {
        cb = options
        options = null
      }
      else {
        cb = cb || noop
      }

      return createMongoosePromise(function (resolve, reject) {
        if (docs == null || docs.length === 0) {
          return resolve(docs), cb(null, docs)
        }

        execute(model, docs, paths, options, defaultOptions, false, function (err, docs) {
          if (err) reject(err), cb(err)
          else resolve(docs), cb(null, docs)
        })
      })
    }
  }
function deepPopulatePlugin ( schema , defaultOptions ) { schema . _defaultDeepPopulateOptions = defaultOptions = defaultOptions || { } /**
     * Populates this document with the specified paths.
     * @param paths the paths to be populated.
     * @param options (optional) the population options.
     * @param cb (optional) the callback.
     * @return {MongoosePromise}
     */ schema . methods . deepPopulate = function ( paths , options , cb ) { return deepPopulate ( this . constructor , this , paths , options , cb ) } /**
     * Populates provided documents with the specified paths.
     * @param docs the documents to be populated.
     * @param paths the paths to be populated.
     * @param options (optional) the population options.
     * @param cb (optional) the callback.
     * @return {MongoosePromise}
     */ schema . statics . deepPopulate = function ( docs , paths , options , cb ) { return deepPopulate ( this , docs , paths , options , cb ) } function deepPopulate ( model , docs , paths , options , cb ) { if ( isFunction ( options ) ) { cb = options options = null } else { cb = cb || noop } return createMongoosePromise ( function ( resolve , reject ) { if ( docs == null || docs . length === 0 ) { return resolve ( docs ) , cb ( null , docs ) } execute ( model , docs , paths , options , defaultOptions , false , function ( err , docs ) { if ( err ) reject ( err ) , cb ( err ) else resolve ( docs ) , cb ( null , docs ) } ) } ) } }
Invoked by Mongoose to executes the plugin on the specified schema.
Invoked by Mongoose to executes the plugin on the specified schema .