Sometimes, we want to populate after save with Mongoose.
In this article, we’ll look at how to populate after save with Mongoose.
How to populate after save with Mongoose?
To populate after save with Mongoose, we can use the populate and execPopulate method after calling save.
For instance, we write
const t = new MyModel(value)
await t.save()
t.populate('my-path').execPopulate()
to call t.save to save t in the database.
Then we call t.populate with the property to populate.
And then we call execPopulate to run the populate operation.
Conclusion
To populate after save with Mongoose, we can use the populate and execPopulate method after calling save.