NumberLong in Mongo shell

时间:2011-08-25 13:33:37

标签: shell mongodb

有没有办法在Mongo shell中使用长整型数据类型?

db.users_stats.find().forEach(function(row) {
    var newRow = row;
    newRow.user_id = new NumberLong(row.user_id);
    newRow.date = new Date(row.date);
    printjson(newRow);
});

JS Error: TypeError: NumberLong is not a constructor mongoConvert.js:3



db.users_stats.find().forEach(function(row) {
    var newRow = row;
    newRow.app_id = NumberLong(row.user_id);
    newRow.date = new Date(row.date);
    printjson(newRow);
});

JS Error: TypeError: NumberLong is not a function mongoConvert.js:3

1 个答案:

答案 0 :(得分:0)

是的,它应该可以正常工作。你看到的错误是邪恶的,我无法重现它们。你使用的是哪个版本?在1.8.1中,我无法重现“NumberLong不是构造函数”错误。

以下适用于我:

db.Test.find().forEach(function(row) {
    var newRow = row;
    if(typeof row.myId == 'number')
        newRow.user_id = new NumberLong(row.myId);
    else if(row.myId instanceof NumberLong)
        newRow.user_id = row.myId;
    printjson(newRow);
});