0

I have nested arrays in a mongodb collection. In my real life situation these take up A LOT of space.

{
    field: 'value',
    field2: 'value',
    scan: [
        [
            {
                array: [0,1,2],
                anotherField: "a"
            },
            {   intfield: 1 },
            {
                array: [0,1,2],
                anotherField: "a"
            },
            {
                array: [0,1,2],
                anotherField: "a"
            },
            {
                array: [0,1,2],
                anotherField: "a"
            },
        ],
        [
            {
                array: [0,1,2],
                anotherField: "a"
            },
            {
                array: [0,1,2],
                anotherField: "a"
            },
            {
                array: [0,1,2],
                anotherField: "a"
            },
            {   intfield: 1 },
            {
                array: [0,1,2],
                anotherField: "a"
            },
        ]
    ]
}

The "array" fields were stored as float64 using pymongo. Is there any way to reduce these from float 64 to float32? Even though they are ints in the example, I need them as floats

Dave
  • 454
  • 1
  • 7
  • 17
  • No single command can do this. You basically need to loop the collection and rewrite things in each document. Either than or write a whole new collection using `aggregate()` and [`$convert`](https://docs.mongodb.com/manual/reference/operator/aggregation/convert/). However there is no such thing as a 32-bit float in BSON types. The `Decimal` type is 64-bit, and `Decimal-128` is actually 128-bit ( if that was not clear from the naming). 8-bytes is really *not so bad*. – Neil Lunn Apr 01 '19 at 10:50
  • See also http://bsonspec.org/spec.html – Neil Lunn Apr 01 '19 at 10:51

0 Answers0