-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
bulkSave promise result, updateResult.getWriteErrorCount is not a function #15314
Comments
I'm unable to repro, the following script works as expected: const mongoose = require('mongoose');
const trackerValueSchema = new mongoose.Schema({ value:{ type: Number, unique: true } });
const TrackerValue = mongoose.model('TrackerValue', trackerValueSchema);
(async () => {
await mongoose.connect('mongodb://127.0.0.1:27017/test');
await TrackerValue.deleteMany({});
const docs = Array.from({ length: 5001 }, (_, i) => new TrackerValue({ value: i }));
await TrackerValue.insertMany(docs);
const toUpdateValues = await TrackerValue.find();
toUpdateValues.forEach((doc) => (doc.value *= 5000));
const updateResult = await TrackerValue.bulkSave(toUpdateValues);
console.log(updateResult.getWriteErrorCount());
await mongoose.disconnect();
})(); Are you passing options to |
…ave writeErrors property Re: #15314
Nope, no options, only array of models to be saved.
It only happen a few times recently, that Sentry was able to catch, both cases indicate multiple request happening for the same model. Given that the actual bulkSave can take 3-6s, it's likely that the same underlying documents are being updated in two separate request 🤔. Even though the logs indicate they are sequential. Note that model is big, have embedded history within the document (so it can grow for frequently updated entries), it also the large collection, over 5 million documents, with a lot of indexes. So it's not easy to reproduce, and it happens quite rarely as you can see, these are all the entries from Sentry we have. I'm on holiday right now. I will try to spend more time on reproducible case once I'm back (10 days) |
fix(model): avoid returning `null` from bulkSave() if error doesn't have writeErrors property
@kYem can you please try upgrading to 8.12.2 and see if that upgrade fixes the issue? |
Prerequisites
Mongoose version
8.8.2
Node.js version
20.18.3
MongoDB server version
6.10.0
Typescript version (if applicable)
5.5.4
Description
This seems to only happen from time to time, maybe cause we are sending a large list of updates, potentially (1-5100) updates in bulk save.
Steps to Reproduce
Unfortunately not easy way to produce. Will try to create separate isolated case, but hopefully even without it would be easy to narrow down when getWriteErrorCount is not a function
Expected Behavior
Should either throw error or TypeScrip types are not correct, as getWriteErrorCount is not always available?
The text was updated successfully, but these errors were encountered: