Convert Double to String MongoDB

3

I have a Double field in a collection in MongoDB and would like to change this field to whole collection to String .

    
asked by anonymous 05.03.2016 / 16:31

1 answer

3
//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

    
05.03.2016 / 16:32