mongoose icon indicating copy to clipboard operation
mongoose copied to clipboard

model.populate does not return an ES6 promise even if mongoose.Promise is set

Open jbdemonte opened this issue 10 years ago • 4 comments

Is it the expected behaviour that model.populate does not return the Promise as defined in mongoose.Promise

  var mongoose = require('mongoose');
  mongoose.Promise = require('bluebird');

  // ...


  User.populate(docs, {path: 'company'})
    .then(console.log)
    .catch(console.errors);

This piece of code throw the error:

TypeError: User.populate(...).then(...).catch is not a function

jbdemonte avatar Jan 05 '16 09:01 jbdemonte

+1 exec not return ES6 promise too =( findById(...).exec(...).then(...).catch is not a function

MniD avatar Jan 06 '16 08:01 MniD

@MniD are you using mongoose 4.x? Are you also setting mongoose.Promise? We have tests in place to make sure exec returns ES6-friendly promises if configured to do so

vkarpov15 avatar Jan 06 '16 17:01 vkarpov15

Model.find(...).populate().exec() returns a promise now but the method does not (tested in mongoose 4.5.8):

var document = new Model(...)
document.populate(...) // does not return a promise

insidewhy avatar Aug 08 '16 14:08 insidewhy

@ohjames expected behavior, use .execPopulate() . the populate() method returns the document so you can chain populate() calls. This issue refers to Model.populate() rather than document.populate()

vkarpov15 avatar Aug 11 '16 22:08 vkarpov15