Search code examples
mongodbnode.jsmongoose

Decimal / Float in mongoose for node.js


I start my first test app on node.js / mongoDB / mongoose, this is a very simple app that aims to crate record in DB and retrieve them.

I create a model like:

var Car = new Schema({
    brand : String,
    speed  : Number,
    date  :  { type: Date, default: Date.now }
});

This is working fine, except that I would like to be able to provide a float value for speed instead of the integer one. I gave a try to Decimal and Float but none of them are working. I did not find in the documentation either.

Any idea ?


Solution

  • I've searched a bit and found this article stating that for storing float values you must use Number type. You can store any float value in speed field.