Node.js的猫鼬中的十进制/浮点数 [英] Decimal / Float in mongoose for node.js
问题描述
我在node.js/mongoDB/mongoose上启动了我的第一个测试应用程序,这是一个非常简单的应用程序,旨在创建数据库中的记录并检索它们.
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 }
});
这很好,除了我希望能够为速度提供浮点值,而不是整数.我尝试了Decimal和Float,但是它们都没有起作用. 我也没有在文档中找到.
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.
有什么主意吗?
推荐答案
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.
这篇关于Node.js的猫鼬中的十进制/浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!