Meteor mongo save/insert 数字转换为字符串
Meteor mongo save/insert numbers are converted to string
我刚刚注意到,每当使用预定义变量在 MongoDB 中保存任何内容时,数据类型都会从 Number 和 Boolean 更改为 String
Orders = new Mongo.Collection("Orders");
Orders.update({_id:"12345"},{$set:{price:5.5}) //this works
var price = {price: 5.5};
Orders.update({_id:"12345"},{$set:price}); //this is not working anymore in the mongo collection price is saved as String "5.5" not as a number, same goes for Boolean values
谁能帮我看看最近的情况?将整个应用程序更改为使用第一种方法不是解决方案,因为我的代码生成了数千个更新,这些更新之前运行良好。
你能不能在声明变量时试试这个:
var price = {price: Number(5.5)};
Orders.update({_id:"12345"},{$set:price});
通过这种方式,我认为它在尝试更新相关数据时可以确保5.5确实是一个数字。对于布尔值,我猜你也可以使用 Boolean(true)
我刚刚注意到,每当使用预定义变量在 MongoDB 中保存任何内容时,数据类型都会从 Number 和 Boolean 更改为 String
Orders = new Mongo.Collection("Orders");
Orders.update({_id:"12345"},{$set:{price:5.5}) //this works
var price = {price: 5.5};
Orders.update({_id:"12345"},{$set:price}); //this is not working anymore in the mongo collection price is saved as String "5.5" not as a number, same goes for Boolean values
谁能帮我看看最近的情况?将整个应用程序更改为使用第一种方法不是解决方案,因为我的代码生成了数千个更新,这些更新之前运行良好。
你能不能在声明变量时试试这个:
var price = {price: Number(5.5)};
Orders.update({_id:"12345"},{$set:price});
通过这种方式,我认为它在尝试更新相关数据时可以确保5.5确实是一个数字。对于布尔值,我猜你也可以使用 Boolean(true)