Answer the question
In order to leave comments, you need to log in
MongoDB: how to change field type from NumberLong to String?
Collection for example:
db.longs.insert({ "_id" : NumberLong("724756511264022954") });
db.longs.insert({ "_id" : 12477933649175871000 });
db.longs.find().forEach( function (x) {
x._id = new String(x._id);
db.longs.save(x);
});
db.longs.find()
{ "_id" : NumberLong("724756511264022954") }
{ "_id" : 12477933649175871000 }
{ "_id" : 12477933649115871000 }
{ "_id" : { "0" : "N", "1" : "u", "2" : "m", "3" : "b", "4" : "e", "5" : "r", "6" : "L", "7" : "o", "8" : "n", "9" : "g", "10" : "(", "11" : "\"", "12" : "7", "13" : "2", "14" : "4", "15" : "7", "16" : "5", "17" : "6", "18" : "5", "19" : "1", "20" : "1", "21" : "2", "22" : "6", "23" : "4", "24" : "0", "25" : "2", "26" : "2", "27" : "9", "28" : "5", "29" : "4", "30" : "\"", "31" : ")" } }
{ "_id" : { "0" : "1", "1" : "2", "2" : "4", "3" : "7", "4" : "7", "5" : "9", "6" : "3", "7" : "3", "8" : "6", "9" : "4", "10" : "9", "11" : "1", "12" : "7", "13" : "5", "14" : "8", "15" : "7", "16" : "1", "17" : "0", "18" : "0", "19" : "0" } }
{ "_id" : { "0" : "1", "1" : "2", "2" : "4", "3" : "7", "4" : "7", "5" : "9", "6" : "3", "7" : "3", "8" : "6", "9" : "4", "10" : "9", "11" : "1", "12" : "1", "13" : "5", "14" : "8", "15" : "7", "16" : "1", "17" : "0", "18" : "0", "19" : "0" } }
db.longs.find().forEach( function (x) {
a = x._id.valueOf().toString();
x._id = new String(a.valueOf());
db.longs.save(x);
});
Answer the question
In order to leave comments, you need to log in
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});
}
});
All template engines are the same, choose the one whose syntax you like.
Do you need to explain why template engines are needed?
What's the point of using templates?
The difference between handlebars and smarty is that one is for javascript and the other is for php. You will not be able to use handlebars in a php project and vice versa.
They have slightly different purposes, HandleBars - used on the client side, Smart - on the server side. So their use can be combined.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question