Model.bulkWrite function never returns on empty ops param and options.ordered = false #14117
Closed
2 tasks done
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Prerequisites
Mongoose version
Introduced in v6.11.3.
Can be reproduces in all other higher versions up to the latest version to date (v8.0.1) .
Node.js version
18.0
MongoDB server version
5.0
Typescript version (if applicable)
No response
Description
The
Model.bulkWrite
function broke after this fix was merged.The
bulkWrite
function never returns whenops = []
andoptions = { ordered: false }
, since the check forif (ops.length === 0) { return cb(null, getDefaultBulkwriteResult()); }
was moved inside the newif (ordered) {
block.A potential solution would be to move the empty
ops
array check above the newif
block and return early from the callback function.Steps to Reproduce
Execute
Model.bulkWrite([], { ordered: false })
for any model. The Node process would get stuck in an endless loop and eventually time out.Expected Behavior
Early return
cb(null, getDefaultBulkwriteResult());
from theModel.bulkWrite
on emptyops
array param.The text was updated successfully, but these errors were encountered: