Something like this should work from the mongo shell:
db.yourCollection.find({}).forEach(function(doc) {
if(isNaN(doc.xyz)) {
print('found string: ' + doc._id);
db.yourCollection.update(
{ _id: doc._id},
{ $set : { "xyz" : parseFloat(doc.xyz) } }
)
}
})
It loops through each document, uses isNaN
as you suggested, then $sets
the value to the parseFloat
value for the current document.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…