nedb icon indicating copy to clipboard operation
nedb copied to clipboard

insert document with Float32Array inside

Open galinkyuchukov opened this issue 5 years ago • 1 comments

Hello!

I have a document , one of its properties is Float32Array.

ex document before insert:

{
    name: 'Test',
    data: Float32Array [ 0.00045, -0.122, ... ]
}

After insert:

{
    name: 'Test',
    data: {
        "0": 0.00045, 
        "1": -0.122,
        ...
    }
}

Is there are any way to keep the array as [0.00045, -0.122, ...] and not converting it to object with numeric properties?

Thank you and best regards!

galinkyuchukov avatar Jun 12 '19 12:06 galinkyuchukov

NeDB does not know what "Float32Array" is, which is why you're getting an error. And arrays can't be assigned that way. Basically, what you want is something like this (as a solution):

{
    name: 'Test',
    data: { Float32Array: [ 0.00045, -0.122, ... ] }
}

Data is now pointing to an object, where its first key ("Float32Array") points to an array. So then you can retrieve one of the array-values like this: data.Float32Array[ 0 ] // This would return 0.00045 and so on.

fexell avatar Aug 23 '19 21:08 fexell