Ask a Question
How do I resolve a "BsonSerializationException": "Element name '\_id' is not valid'. " when trying to use the CRUD Update Extension for Mongo?
Currently, I have a problem with the CRUD Update extension for Mongo. It requires the ID as string and the document to update.
The Document to update is derived from StorageDocument where the ID is a string field. However when the document is sent to UpdateOneAsync the ID is converted to an ObjectID for the filter. Still, the document is sent as is including the _id field as String rather than ObjectID. That results in a BsonSerializationException": "Element name '_id' is not valid'. So a CREATE, GET, UPDATE does not work.
Also DateTime values are a problem. GET with a DateTime and without any change Update fails because of the same issue (I guess wrong type: BsonSerializationException" "Element name 'CreatedAt' is not valid'." ). It all seems that the BsonSerializer is different than for CREATE and GET. All these fields work fine creating and also get returns the same values. Only Update results in a problem and values are completly unchanged. For ID it helps to set it to null but for DateTime fields that dosn't work.