function patchQueryPrototype() {
    var Query = mongoose.Query
      , _exec = Query.prototype.exec

    if (Query.prototype.deepPopulate != null) {
      return
    }

    /**
     * Registers deep population on this query.
     * @param paths the paths to be populated.
     * @param options (optional) the population options.
     * @remark this method can only be invoked once per query.
     * @return {Query}
     */
    Query.prototype.deepPopulate = function (paths, options) {
      if (this.model.schema.methods.deepPopulate == null) {
        throw new Error('Plugin was not installed')
      }

      if (this._deepPopulates) {
        throw new Error('deepPopulate was already invoked')
      }

      this._deepPopulates = {paths: paths, options: options}
      return this
    }

    /**
     * Monkey-patches `exec` to add deep population hook.
     * @param op the operation to be executed.
     * @param cb the callback.
     * @return {MongoosePromise}
     */
    Query.prototype.exec = function (op, cb) {
      var deepPopulate = this._deepPopulates
      if (!deepPopulate) {
        return _exec.call(this, op, cb)
      }

      var model = this.model
        , paths = deepPopulate.paths
        , options = deepPopulate.options
        , defaultOptions = model.schema._defaultDeepPopulateOptions
        , lean = this._mongooseOptions.lean

      if (isFunction(op)) {
        cb = op
        op = null
      }
      else {
        cb = cb || noop
      }

      return createMongoosePromise(function (resolve, reject) {
        _exec.call(this, op, function (err, docs) {
          if (err) {
            return reject(err), cb(err)
          }

          if (!docs) {
            return resolve(docs), cb(null, docs)
          }

          execute(model, docs, paths, options, defaultOptions, lean, function (err, docs) {
            if (err) reject(err), cb(err)
            else resolve(docs), cb(null, docs)
          })
        })
      }.bind(this))
    }
  }
Patches Query prototype to add `deepPopulate()` method.