db.longs.find().forEach( function (x) {
var oldId = x._id;
var updateFlag = false;
if (typeof x._id == "number") {
updateFlag = true;
x._id = x._id+"";
} else if(x._id instanceof NumberLong) {
updateFlag = true;
x._id = x._id.toNumber().toString();
}
if (updateFlag) {
db.longs.save(x);
db.longs.remove({"_id":oldId});
}
});