Wednesday 21 March 2018

how to populate (mongo) a field on the req.user ?

One field in my User collection looks like this:hearts: [{ type: mongoose.Schema.ObjectId }], I'm trying to populate the objectID so I have access to all the other dataNormally I'm familiar running autopopulate function in mongo:function autopopulate(next) { this.populate("hearts"); next(); } userSchema.pre("find", autopopulate); userSchema.pre("findOne", autopopulate); But because the object is on the req.user, I'm not using "find" or "findOne" in my controller. I'm just passing req.user directly into my views.Massive thanks for any help!

Submitted March 21, 2018 at 02:01PM by harrydry

No comments:

Post a Comment