Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

mongodb truncation exception c#

//This means that there was an exception casting from a more detailed object to a less

//Solution A:
JObject.Parse(
  JsonConvert.SerializeObject(
    BsonTypeMapper.MapToDotNetValue(bson)
  )
);

//Solution B: mapping and setting allowTruncation: true
//This is done at the startup level

BsonSerializer.RegisterSerializer(
                typeof(float),
                new DoubleSerializer(
                    BsonType.Double,
                    new RepresentationConverter(
                        allowOverflow: true,
                        allowTruncation: true
                    )
                )
            );
 
PREVIOUS NEXT
Tagged: #mongodb #truncation #exception
ADD COMMENT
Topic
Name
6+3 =