Is there any way how to use long integer data type in Mongo shell?
db.users_stats.find().forEach(function(row) {
var newRow = row;
newRow.user_id = new NumberL开发者_运维百科ong(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
Yes, it should work fine. The errors you're seeing are wicked, I can't reproduce them. Which version are you using? In 1.8.1
, I can't reproduce the "NumberLong
is not a constructor" error.
The following works for me:
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);
});
精彩评论