I have a Double
field in a collection in MongoDB and would like to change this field to whole collection to String
.
I have a Double
field in a collection in MongoDB and would like to change this field to whole collection to String
.
//inteiro para string
db.temp.find({name: {$exists:true}}).forEach( function(x) {
db.temp.update({_id: x._id}, {$set: {name: x.name.toString()}});
});
//string para data
db.temp.find({name: {$exists:true}}).forEach( function(x) {
db.temp.update({_id: x._id}, {$set: {name: ISODate(x.name}});
});
//string para inteiro
db.temp.find({name: {$exists:true}}).forEach( function(x) {
db.temp.update({_id: x._id}, {$set: {name: NumberInt(x.name)}});
});
Source: link