document.execPopulate() not returning promise
See original GitHub issueMy 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
Issue Analytics
- State:
- Created 8 years ago
- Comments:27
Top Results From Across the Web
Does Model.populate() return a promise? - node.js
I have two code snippets, both use populate() on a Model however one code snippet requires execPopulate() to return a promise but the...
Read more >Document.prototype.unmarkModified() - Mongoose
If the path was not provided, then all populated fields are returned to their unpopulated state. Document.prototype.directModifiedPaths(). Returns: «Array».
Read more >Mongoose API v4.4.14
Mongoose#Document() ... When no collection argument is passed, Mongoose produces a collection name by ... execPopulate() // executed, returns promise ...
Read more >Creating a Promise Helper Function for your Mongoose App
execPopulate() .then(user => { res.render('newDesign/blog', { cart_items: user.cart.items, ... getShoppingCartData = req => { return new Promise((resolve, ...
Read more >文档API - Mongoose文档
Called internally after a document is returned from mongodb. ... If you want to use promises instead, use this function with execPopulate(). 示例....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.