如何在流星中存储整数(numberLong)?

时间:2013-08-14 22:01:35

标签: meteor

我试图将财务数据插入到集合中,因此我想明确地将我的Javascript数字转换为NumberLongs。遗憾的是,以下内容并不奏效:

  var myValue = parseInt('13', 10);
  Finance.insert({
    bal1: NumberLong(myValue),
  });

使用Meteor执行此操作的正确方法是什么?

2 个答案:

答案 0 :(得分:0)

var myValue = parseInt('13', 10);
Finance.insert({
    stats: {
        bal1: NumberLong(myValue)
    }
});

只要NumberLong()作为方法存在,上述应该有效。 Mongo根据文档支持您要查找的数字类型。

答案 1 :(得分:0)

回答我自己的问题。 根据我的帖子: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确实收到了回来的号码。

考虑到:

  • 根据ECMA:“注意所有正负整数 其幅度不大于2 ^ 53可代表 数字类型
  • 想要 mongo存储为numberLong如果确实很长

......我们现在应该很好:)