mongoose: document.execPopulate() not returning promise
My promise chain looks like this:
myDocument.save()
.then(function (savedDocument) {
return MyModel.update(/*query, options*/).exec();
})
.then(function () {
return myDocument
.populate(/*path, select, model*/)
.populate(/*path, select, model*/)
.execPopulate(); // server/controllers/my-document.server.controller:236:10
})
.then(function (populatedDoc) {
//do stuff with populatedDoc
});
However, I’m getting the following stack trace:
TypeError: undefined is not a function
at Object.populate (node_modules/mongoose/lib/document.js:2028:22)
at Object.Document.execPopulate (node_modules/mongoose/lib/document.js:2070:8)
at server/controllers/my-document.server.controller.js:236:10
at newTickHandler (node_modules/mongoose/node_modules/mpromise/lib/promise.js:229:18)
at wrapped (node_modules/newrelic/lib/transaction/tracer/index.js:157:28)
at process._tickDomainCallback (node.js:381:11)
at process.wrappedFunction (node_modules/newrelic/lib/transaction/tracer/index.js:262:51)
which, looking at the source code, means that the didn’t find anything on S/O about this… I’ll happily move this question there, but this looks to me like a bug since the documentation says I should be able to do this.Document
object’s constructor does not have a populate method? scratch that, I’m quite confused, and
For reference I’m using Mongoose v4.0.x
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 27
@swordsreversed
execPopulate()
is a function on a document, not a query. So the below requiresexecPopulate()
:Your approach attaches populate to the query, so what you need is:
Please review the promises docs for more info.
Hi I’m getting a similar problem with
returning a stacktrace of
Also i’m putting in
to use ES6 through Babel. Mongoose is 4.4.3. Not really sure how to proceed after reading this thread. Any help would be appreciated.