Undocumented breaking change in v7: calling diffIndexes
throws error when collection does not exist
#14010
Closed
2 tasks done
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Prerequisites
Issue
In Mongoose 6, if you called
await Model.diffIndexes()
on a model where the collection does not yet exist, it would return the index diff and let you proceed with things likeawait Model.syncIndexes()
. I suppose it would create the collection first - but I haven't verified this.In Mongoose 7, it will throw an error instead:
It throws even if you have
autoCreate: true
set on the globalmongoose
instance.I suppose the fix is to call
await Model.createCollection()
first, but still this was a breaking change that is not listed in the release notes or migration guide as far as I can see.I created a small demo where you can see the issue here: https://codesandbox.io/p/sandbox/quirky-kapitsa-49vy78?file=%2Findex.js%3A5%2C1
The text was updated successfully, but these errors were encountered: