Command update failed: bson length doesn't match what we found in object with unknown _id

I am using the C# Driver (2.10.1) and I periodically get this error and I cannot find anything online so far.

“Command update failed: bson length doesn’t match what we found in object with unknown _id.”

I am updating a single document. I am really at a loss, any help would be appreciated.

Mike

I believe this might be to do with the BSON.ObjectId not matching to the class you’re using, are you decorating the model with something like:

[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }

Mongo will automatically create an Id property when you don’t have one on your model but I’ve always found it safer to set one explicitly

Hi @Michael_Harris, welcome!

I am updating a single document. I am really at a loss, any help would be appreciated.

If the suggestion from @Will_Blackburn does not solve your problem, could you provide a code snippet of the update operation that could reproduce the problem ?

Regards,
Wan.

Hi,

We also experience this issue on a regular basis. It seems to occur mostly (if not only) within a Docker container. We use the 4.2.1-bionic image from Docker Hub, but have tested with a bunch more, including 4.2.3 and the latest 4.2.5

Driver: NodeJS 3.5.2
Server: 4.2.1
Problem: Incidental error about unknown_id, see stacktrace below
Environment: Kubernetes v1.14.8. Mongo uses a single-RW persistent EXT4-volume.

Note that we have not seen this on a non-Dockerized environment before. The only occasions in which this has occurred so far is within our CI (Gitlab-CI, same Docker image as on Kubernetes) and within Kubernetes.

The stacktrace we get is:

MongoError: bson length doesn't match what we found in object with unknown _id
bson length doesn't match what we found in object with unknown _id: MongoError: bson length doesn't match what we found in object with unknown _id
    at MessageStream.messageHandler (/usr/src/app/indy/Indy/node_modules/mongodb/lib/cmap/connection.js:253:20)
    at MessageStream.emit (events.js:311:20)
    at processMessage (/usr/src/app/indy/Indy/node_modules/mongodb/lib/cmap/message_stream.js:140:12)
    at MessageStream._write (/usr/src/app/indy/Indy/node_modules/mongodb/lib/cmap/message_stream.js:66:7)
    at doWrite (_stream_writable.js:441:12)
    at writeOrBuffer (_stream_writable.js:425:5)
    at MessageStream.Writable.write (_stream_writable.js:316:11)
    at Socket.ondata (_stream_readable.js:714:22)
    at Socket.emit (events.js:311:20)
    at addChunk (_stream_readable.js:294:12)
    at readableAddChunk (_stream_readable.js:275:11)
    at Socket.Readable.push (_stream_readable.js:209:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:186:23)

Same issue with Golang mongo-driver v1.10.1 and mongo:4.2 docker image.