When attempting to add new data to an array using mongoose, I encountered two errors. Here is the code snippet in question:
return await db.fileMeta.findOneAndUpdate({
username: username,
'files.fileUID': {
$ne: data.fileUID
}
}, {
$addToSet: {
files: data
}
}).exec();
The JavaScript object data
contains 25 items totaling 789
bytes, far below the 16MB limit. However, my previously working code started throwing the following error recently:
MongoError: BSONObj size: 16829075 (0x100CA93) is invalid. Size must be between 0 and 16793600(16MB) First element: $v: 1
at MessageStream.messageHandler (/home/user/projects/web-app/node_modules/mongoose/node_modules/mongodb/lib/cmap/connection.js:268:20)
...
After resolving the above error, I encountered another one:
MongoError: Resulting document after update is larger than 16777216
at MessageStream.messageHandler (/home/user/projects/web-app/node_modules/mongoose/node_modules/mongodb/lib/cmap/connection.js:268:20)
...
Inspecting MongoDB Compass revealed a total size of 16.2MB
. While this matches the limit set by the error, it is puzzling since the data
object is significantly smaller. How do I address this issue effectively?