mongoose-fill icon indicating copy to clipboard operation
mongoose-fill copied to clipboard

Mongoose hooks

Open armand1m opened this issue 7 years ago • 2 comments

Hey there, thanks for contributing for open source. I was using in your package for integrating some firebase data into something I'd need, and I wonder if it is possible to use this inside of schema.pre('find', callback) callbacks for example. Something like this:

schema.fill('user', function(callback) {
  if (this.userFirebaseUid) {
    return FirebaseAdmin
      .auth()
      .getUser(this.userFirebaseUid)
      .then(user => {
        callback(null, user.providerData[0])
      })
      .catch(err => {
        callback(err, null);
      })
  }

  callback();
});

const autoPopulateRefs = function autoPopulateRefs(next) {
  this.fill('user');
  this.populate('source');
  this.populate('category');

  next();
}

schema
  .pre('findOne', autoPopulateRefs)
  .pre('find', autoPopulateRefs);

armand1m avatar Nov 02 '17 21:11 armand1m

I wonder if it is possible to use this inside of schema.pre('find', callback) callbacks

I don't know, does it work? =)

wclr avatar Nov 03 '17 10:11 wclr

@whitecolor no, it doesn't :(

armand1m avatar Nov 03 '17 11:11 armand1m