Value 0 in Atlas collection field fails to sync to realm field of type float and decimal

We have a collection in an Atlas database. This collection has a field that takes decimal value. The collection is mapped in a Realm app as a field of type float. Sync is activated on this realm app.

When a document is inserted in the Atlas collection with value of this field as 0, the record fails to sync with the Realm app.

“Detailed Error: could not convert MongoDB value to Realm payload for { table: work_order_section_item, path: min }, value=0 : cannot transform int value for non-int property of type float”

If the value is non zero decimal, it works fine. I tried mapping the field to float as well as double. Same results.

How are you inserting the document into Atlas? Depending on the driver you may need to explicitly cast the value type as float upon insertion

I am using the mongodb javascript driver. I have a script that calls a third party REST API to get an array of documents. The objects in array contain all values as strings but there is a type definition in the input array. If the input object is

{
        "id": {
            "type": "string",
            "value": "f530dac6db8630509b3a3632f39619ca"
        },
        "name": {
            "type": "string",
            "value": "temperature"
        },
        "min": {
            "type": "decimal",
            "value": "4.2"
        },
        "max": {
            "type": "decimal",
            "value": "6.4"
        }
    }

I am transforming it into

{
        "_id": "f530dac6db8630509b3a3632f39619ca",
        "name": "temperature",
        "min": 4.2,
        "max": 6.4
}

i.e. when type is decimal I am using parseFloat(value) to convert incoming string to float. Finally I am calling insertMany() on the collection with array of transformed objects as input.

Insert to Atlas collection works for any value but when the value is an integer the sync to Realm fails.

“Detailed Error: could not convert MongoDB value to Realm payload for { table: work_order_section_item, path: max }, value=5 : cannot transform int value for non-int property of type double”

At the moment I have set the Realm attribute type as double but I was getting similar errors when the type was float.
I reckon javascript will treat 5.0 as 5 or 0.0 as simply 0. Not sure why int is not automatically transformed to float/double.

Hello,

Were you able to find a suitable fix to this? I am experiencing the same problem.