BSONObj size: 24720183 (0x1793337) is invalid. Size must be between 0 and 16793600(16MB)

Hi Guys,
I am using Mongo Version 4.4 and Debezium 2.1.
I need to move all the data from mongo 4.4 to mongo 7.
Once i started the connector and got the following error :

Caused by: com.mongodb.MongoCommandException: Command failed with error 10334 (BSONObjectTooLarge): ‘BSONObj size: 24720183 (0x1793337) is invalid. Size must be between 0 and 16793600(16MB) First element: _id: { _data: “XXX” }’ on server db-mongo-X.X.X.net:27017.

How can i fix this issue ? break this documents into pieces ? this is an invalid document? can i repair it ?

Hi Bar,

Yes, you’ll need to move or break apart the document that is invalid. The maximum document size is 16 MB https://www.mongodb.com/docs/manual/reference/limits/#mongodb-limit-BSON-Document-Size .

For migrating from MongoDB 4.4 to 7.0, do you have separate instances setup and are copying data between them? Or are you updating in place? I ask because that is a big jump in terms of major versions.

1 Like

Do you know how I can break the document before it reaches Debezium?

My main issue is that Debezium sends the event twice—both before and after the change. This duplication is causing a sizing issue for me. When I configure Debezium to send only the “after” document by setting "capture.mode": "change_streams", it causes multiple issues because it has missing fields, like _id sometimes.

Essentially, I am consuming data from Kafka and inserting it into the new MongoDB version 7.

debezium version is 2.1 which is very old.
Any guidance or suggestions would be greatly appreciated!

Hi Bar,

Would you please share examples for the before and after documents? As well as the desired final document?

This will help me suggest options that will fit your use case.