我正在尝试将财务数据插入到集合中,因此我想明确地将我的 Javascript 数字转换为 NumberLongs。不幸的是,以下方法不起作用:
var myValue = parseInt('13', 10);
Finance.insert({
bal1: NumberLong(myValue),
});
使用 Meteor 执行此操作的正确方法是什么?
我正在尝试将财务数据插入到集合中,因此我想明确地将我的 Javascript 数字转换为 NumberLongs。不幸的是,以下方法不起作用:
var myValue = parseInt('13', 10);
Finance.insert({
bal1: NumberLong(myValue),
});
使用 Meteor 执行此操作的正确方法是什么?
var myValue = parseInt('13', 10);
Finance.insert({
stats: {
bal1: NumberLong(myValue)
}
});
只要作为NumberLong()
一种方法存在,上述方法就应该起作用。Mongo 支持您根据文档查找的数字类型。
回答我自己的问题。根据我的帖子:https ://groups.google.com/forum/#!topic/meteor-talk/o_co6nRjoYU
我相信在 0.6.5 中解决了读取问题,当时 Meteor 将 MongoDB 驱动程序从 1.3.7 升级到 1.3.17。
https://github.com/mongodb/node-mongodb-native/blob/master/HISTORY:
1.3.13 2013-07-31
- Added promoteLongs option for to allow for overriding the promotion of Longs to Numbers and return the actual Long.
在http://mongodb.github.io/node-mongodb-native/api-generated/db.html:
Db()
promoteLongs {Boolean, default:true}, when deserializing a Long will fit it into a Number if it’s smaller than 53 bits
我已经检查过了,Meteor 确实确实再次收到了号码。
考虑到:
...我们现在应该很好:)