Database

db={foos:[{"values":[{"foo":"12"},{"foo":"34"},{"foo":"56"}]}]}

Query

db.foos.aggregate([{"$match":{"$expr":{"$eq":[{"$type":"$values"},"array"]}}},{"$set":{"values":{"$map":{"input":"$values","in":{"$cond":{"if":{"$eq":[{"$type":"$$this.foo"},"string"]},"then":{"$mergeObjects":["$$this",{"foo":{"$toDecimal":{"$trim":{"input":"$$this.foo"}}}}]},"else":"$$this"}}}}}},{"$merge":{"into":"foos","on":"_id","whenMatched":"replace"}}])

Result