Answer the question
In order to leave comments, you need to log in
How to properly organize relationships on Mongoose?
Good evening. The question arose about how best to organize relationships between Mongoose models.
For example, we have two models: User and UserRecovery.
// Schema модели User
var schema = mongoose.Schema({
// ....
_recovery: {type: mongoose.Schema.ObjectId, ref: 'UserRecovery'}
});
// Schema модели UserRecovery
var schema = mongoose.Schema({
// ....
_user {type: mongoose.Schema.ObjectId, ref: 'User'}
});
var userRecovery = new UserRecovery({_user: objectId('...')});
userRecovery.save(function(err, createdUserRecovery) {
console.log(createdUserRecovery._user.username);
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question