Skip to content

Instantly share code, notes, and snippets.

@felipsmartins
Last active November 14, 2017 20:22
Show Gist options
  • Select an option

  • Save felipsmartins/cb9af94503b1f45ce2b128ebd14daa3c to your computer and use it in GitHub Desktop.

Select an option

Save felipsmartins/cb9af94503b1f45ce2b128ebd14daa3c to your computer and use it in GitHub Desktop.
//convertendo de string para inteiro / string to int (não usar parseInt() pois pode transformar para Double em mongo shell)
db.consumidores.find({ 'cod_revendedor': { $type : "string" } }).forEach(function (doc) {
doc.cod_revendedor = NumberInt(doc.cod_revendedor);
db.consumidores.save(doc);
});
db.registro_visitas.find().forEach(function(doc) {
db.registro_visitas.update({_id: doc._id}, {$set: {motivoInconformidade: parseInt(doc.motivoInconformidade)}});
});
//print(db.registro_visitas.find());
db.cadernos_digitados.find().forEach(function(doc) {
db.cadernos_digitados.update({_id: doc._id}, {$set: {digitadorId: doc.digitadorId.toString() }});
});
db.cadernos_digitados.find().forEach(function(doc) {
if (typeof doc.digitadorId == 'undefined') {
print(doc._id);
}
})
// converter para string campos digitadorId quando do tipo int-32: 16
db.cadernos_digitados.find({$and: [{digitadorId: {$exists: true}}, {digitadorId: {$type: 16}} ]}, {digitadorId:1}).forEach(function(doc) {
if (typeof doc.digitadorId == 'number') {
db.cadernos_digitados.update({_id: doc._id}, {$set: {digitadorId: doc.digitadorId.toString() }});
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment