Skip to main content
Updated the answer to fit the recent version of the mongoose.js api. Old answer is kept intact without altering for those who will use version 5.X and lower.
Source Link

The solution for me was to use execPopulate, like so

const t = new MyModel(value)
return t.save().then(t => t.populate('my-path').execPopulate())

Update

Mongoose 6.X and up: .execPopulate() is removed and .populate() is no longer chainable

The above code should be written like:

const t = new MyModel(value)
return t.save().then(t => t.populate('my-path')) // Returns a promise

If you don't want a promise:

return t.save().then(t => t.populate('my-path')).then(t => t)

Since it is no longer chainable, the new way to populate multiple fields is to use an array or an object:

return t.save().then(t => t.populate(['my-path1', 'my-path2'])).then(t => t)

Resources:

The solution for me was to use execPopulate, like so

const t = new MyModel(value)
return t.save().then(t => t.populate('my-path').execPopulate())

The solution for me was to use execPopulate, like so

const t = new MyModel(value)
return t.save().then(t => t.populate('my-path').execPopulate())

Update

Mongoose 6.X and up: .execPopulate() is removed and .populate() is no longer chainable

The above code should be written like:

const t = new MyModel(value)
return t.save().then(t => t.populate('my-path')) // Returns a promise

If you don't want a promise:

return t.save().then(t => t.populate('my-path')).then(t => t)

Since it is no longer chainable, the new way to populate multiple fields is to use an array or an object:

return t.save().then(t => t.populate(['my-path1', 'my-path2'])).then(t => t)

Resources:

Source Link
François Romain
  • 14.5k
  • 17
  • 94
  • 128

The solution for me was to use execPopulate, like so

const t = new MyModel(value)
return t.save().then(t => t.populate('my-path').execPopulate())