Populate does not work with cursor(), but works with exec()
See original GitHub issueI’m running Mongoose 4.4.20 with Mongo 3.0.12.
These are the relevant parts of my schema:
var ObjectId = mongoose.Schema.Types.ObjectId
var campaignSchema = mongoose.Schema({
// ...
summary: { type: ObjectId, ref: 'summaries' },
// ...
}
var summarySchema = mongoose.Schema({
// ...
}
var Campaign = mongoose.model('Campaign', campaignSchema, 'campaigns')
var Summary = mongoose.model('Summary', summarySchema, 'summaries')
If I use regular exec
, it works just fine:
Campaign.find({
...
})
.populate('summary')
.exec()
.then(function (data) {
console.log(data)
})
However, if I try the same with cursor
, it does not work: the summary
field is not populated:
var cursor = Campaign.find({
...
})
.populate('summary')
.cursor()
cursor.next().then(function (data) {
console.log(data)
})
The code above only shows the refs’ ObjectId
instead of the full document.
Edit
I’m really sorry, there might be an error when I copy-pasted the code. That extra .exec
does not exist.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Mongoose populate works with exec() but not with cursor()
summary field is not populated, returning only the ObjectId referenced by the model. Edit. Here are the relevant parts of my schemas: var...
Read more >Mongoose populate works with exec() but not with cursor()
Coding example for the question Mongoose populate works with exec() but not with cursor()-mongodb.
Read more >Working with cursors and dynamic queries in PL/SQL
When you are fetching a single row, use SELECT-INTO or EXECUTE IMMEDIATE-INTO (if your query is dynamic). Do not use an explicit cursor...
Read more >ORM Querying Guide - SQLAlchemy 1.4 Documentation
The select() construct accepts ORM entities, including mapped classes as well as class-level attributes representing mapped columns, ...
Read more >Faster Mongoose Queries With Lean
In this tutorial, you'll learn more about the tradeoffs of using lean() . ... that the Person model's getters and virtuals don't run...
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
@zoellner opened up a new issue #5334 to track, keeping this issue closed ☝️
I am seeing the same issue. code to reproduce below. There are a few options to populate and I’m not seeing a difference. It seems that the model option is ignored
link1 is populated as expected (there is no difference when changing the model options, no error when using the
model: 'asdf'
option) link2 is always null after the population when using cursorcode to reproduce:
code output: