Search code examples
rmongodb

change field type from rmongodb


I have a collection uploaded to rmongodb. The issue is that all the fields were defined as strings. Thus, my aggregations are not working properly. I've looked through the documentation and it is not clear to me how I would update the field type. I have tried:

mongo.update(mongo, "airRail07", 
             '{"PAID_FARE_USD":{"$type":2}}',
             '{"PAID_FARE_USD":{"$type":1}}')

but, that did not seem to do the trick. Any ideas?

Edit 1

After looking around I've changed the update command as follows:

m1 <- mongo.bson.from.JSON('{"PAID_FARE_USD":{"$type":2}}')
m2 <- mongo.bson.from.JSON('{"$set": {"PAID_FARE_USD":{"$type":1}}}')

mongo.update(mongo, "airRail07", list(m1), list(m2))

This returns TRUE but they $type is not changed.

Thanks,

Carlos


Solution

  • Seems you can't cast types internally - MongoDB: How to change the type of a field? you can only iteratively update each value.