Convert Double to String Mongodb

Asked

Viewed 237 times

3

I own a field Double in a Collection on Mongodb and would like to exchange this field in every collection to String.

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: http://codigosimples.net/2016/03/05/conversao-de-tipos-com-mongodb/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.