mongoosejs / mongoose-double

Provides Double support for mongoose.js
MIT License
18 stars 13 forks source link

DoubleType addition is treated as string concatenation #7

Closed stieg closed 5 years ago

stieg commented 5 years ago

See script below:

> var a = new mongoose.Types.Double(3);
undefined
> var b = new mongoose.Types.Double(50);
undefined
> a + b;
'350'
stieg commented 5 years ago

This is due to the override of the valueOf method. To work around an issue related to cloning the DoubleType class implements a version of valueOf that simply returns this. Changing the method to return this.value fixes this bug but causes an issue with cloning. What to do...?