IntDecodeValue can only truncate float64 to an integer type when truncation is enabled

Hi,

The error you’re seeing in the aggregation is expected because decoding would lose precision and therefore could result in data loss. I’m not sure why you’re not seeing the error when using Find because the Cursor returned by Find and Aggregate is the same, so the Decode code path should be the same. Is it possible that the filter you’re providing to Find is filtering out the document so it’s never returned? If not, can you share the code you’re using for Find as well as the definition of the struct you’re decoding into?

If you want the driver to ignore the precision loss and truncate each float into an integer, you can use the trunacte struct tag:

type Foo struct {
    Coordinates []int `bson:"coordinates,truncate"`
}

This will tell the driver that you’re opting into truncating any floats into integers, even if that will cause loss of precision.

– Divjot