Luc Luc - 3 years ago 151
Node.js Question

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 ?

Answer Source

I am not familiar with mongoose and node.js at all, but I've searched a bit and found that for storing float values you must use Number type. You can store any float value in speed field. Article.

Hope this help.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download