MMind
MMind

Reputation: 1915

Mongoose inserts Number as Int32 or double, how to force to always use double, like the shell does

when a field is of type Number, mongoose will insert it as Int32 or double depending on the actual value:

5 -> Int32 5.3 -> double

Effectively the same field has different types depending on the entity inserted.

This is not an issue to read/write from javascript as both are converted to Number. However, if you are simultaneously using a driver from a strong typed language with both types, like C#, this becomes an issue.

Is it possible to configure mongoose to insert the Number always as double, like the mongo shell does?

Upvotes: 7

Views: 3363

Answers (1)

aaronheckmann
aaronheckmann

Reputation: 10790

Use the mongoose-double type for that.

Upvotes: 4

Related Questions