Answer the question
In order to leave comments, you need to log in
How to do binding in mongoose?
For the user to participate in groups, I did it like this
"members" : [
"54bd0fa565bf53efd76210b7",
],
Answer the question
In order to leave comments, you need to log in
// ...
var UserSchema = new Schema({
name: String,
email: {type: String, lowercase: true},
contracts: [{
type: Schema.Types.ObjectId,
ref: 'Contract'
}]
});
module.exports = mongoose.model('User', UserSchema);
// ...
User.findOne({
_id: userId
}, '-salt -hashedPassword')
.populate('contracts')
.exec(function(err, user) { // don't ever give out the password or salt
if (err) return next(err);
if (!user) return res.json(401);
// user.contracts.forEach(function(contract, index){ console.log(index, contract); });
res.json(user);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question