mongoose-fill
mongoose-fill copied to clipboard
Mongoose hooks
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);
I wonder if it is possible to use this inside of schema.pre('find', callback) callbacks
I don't know, does it work? =)
@whitecolor no, it doesn't :(