Is there an equivalent for $toInt in versions prior to 4.0
With aggregation along I do not believe so. You could query for the documents and then
map over them in your application to convert the types you want.
I could be missing something if anyone else knows different.
I don’t know much about the older versions of MongoDB but if $toInt is new, I would imagine that you can perform the conversion using python in combination with a collection update.
I.e. query using $type to filter out the string field docs, then loop through the resulting docs in Python and perform the bulk update.
I’m surprised that such a basic operation wasn’t available from the beginning.
Thanks for the replies guys. Was hoping there was a simpler workaround in an aggregation.