New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.populate() -> .batchSize() -> .cursor() populates docs in batch then again one-by-one #11509
Comments
Further investigation showing me that lib/model.js:L4467 passes in the following options but it doesn't look like it's using those PopulateOptions as cache.
|
I think I am able to reproduce your issue but what should the mongodb calls look like then?
edit: I see it now, the first in operation has both object ids and then it follows up with two more, one each |
const mongoose = require('mongoose');
mongoose.set('debug', true);
const testSchema = new mongoose.Schema({
name: String,
citation: {
type: mongoose.Types.ObjectId,
ref: 'OtherModel'
}
});
const otherSchema = new mongoose.Schema({
citation: String
});
const Test = mongoose.model('Test', testSchema);
const otherModel = mongoose.model('OtherModel', otherSchema);
async function run() {
await mongoose.connect('mongodb://localhost:27017');
await mongoose.connection.dropDatabase();
const entry = await otherModel.create({
citation: 'Stop'
});
const otherEntry = await otherModel.create({
citation: 'Speeding'
});
const test = await Test.create({
name: 'Test Testerson',
citation: entry._id
})
const otherTest = await Test.create({
name: 'Test Testerson',
citation: otherEntry._id
});
const cursor = Test.find({name: 'Test Testerson'}).populate('citation').batchSize(2).cursor();
for await (const doc of cursor) {
// console.log('The doc', doc);
}
}
run(); |
I think this means also that the typings are not correct. Like #11503 |
Do you want to request a feature or report a bug?
bug
What is the current behavior?
.populate() -> .batchSize() -> .cursor()
currently calls populate with respected batchSize then calls populate for each doc again, one-by-one.If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
Should populate 2 and not populate one by one after.
Related issues?
#9365
As far as I can tell
pop
was dropped in this refactor commit:e49a1f6
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
node 16.14.0
mongodb 4.4.12
mongoose 6.2.4
The text was updated successfully, but these errors were encountered: