The sample code is as follows:
var UserSchema = new Schema({
interactions: [{
interactor: {
type: Schema.Types.ObjectId,
ref: 'User'
}
}]
});
Now I want to match all interactor with userId according to userId. how can I do this with mongoose?
I have found a solution to the matching problem, which is very intuitive:
User.find({ 'interactions.interactor': mongoose.Types.ObjectId(user._id) }, function (err, users) { }
However, in the callback function, I will update the matching users. How should I save the updates after updating? Without the method of users.save (), do you have to write loop save yourself?