P
P
Pavel Bagro2015-11-20 18:43:32
Mongoose
Pavel Bagro, 2015-11-20 18:43:32

How to update populated fields?

Is it possible to change the data in a related document?
Something like this:

User.findById(id).populate('profile').exec(function(err, user) {
  user.profile.description = newDescription;
  user.save();
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Voischev, 2015-12-03
@voischev

Maybe so?

User.findById(id).populate('profile').exec(function(err, user) {
  Profile.findOneAndUpdate({ _id: user.profile }, { description: newDescription });
  user.save();
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question