Thanks for your response. I was unclear in my initial question in that I did not want to have to specify the fields to update to numbers, but rather walk each property and perform the check.
I have put together this little function to do the trick:
var cursor = db.results.find();
while (cursor.hasNext()) {
var doc = cursor.next();
for (key in doc) {
if (key.match(/^metric_.*/i) && !isNaN(doc[key])) {
doc[key] = parseFloat(doc[key]);
db.results.update({ _id : doc._id }, doc );
}
}
}
Two things to note:
- This only does the check and conversion to the first level of properties. It can be easily modified to go deeper, but this was all I needed at this time.
- This function will blast your date values away!!! A javascript date is evaluated by
isNaN as false, and therefore will be treated as a number. In my case, using parseFloat will actually set the value to isNaN. Again, a very easy fix for the onlooker, but I just wanted to provide that disclaimer.
Hope this helps someone else in my position.