I encountered the same issue,
E:\Web Development Bootcamp\Projects\todolist-v2\node_modules\mongoose\lib\model.js:3519
for (let i = 0; i < error.writeErrors.length; ++i) {
^
TypeError: Cannot read properties of undefined (reading ‘length’)
at E:\Web Development Bootcamp\Projects\todolist-v2\node_modules\mongoose\lib\model.js:3519:47
at collectionOperationCallback (E:\Web Development Bootcamp\Projects\todolist-v2\node_modules\mongoose\lib\drivers\node-mongodb-native\collection.js:150:26)
at Timeout. (E:\Web Development Bootcamp\Projects\todolist-v2\node_modules\mongoose\lib\drivers\node-mongodb-native\collection.js:177:11)
at listOnTimeout (node:internal/timers:564:17)
at process.processTimers (node:internal/timers:507:7)
Node.js v18.13.0
when i change the localhost to 127.0.0.1 in the connection → It worked.
This may help you to narrow down the issue.