The issue I have is making a conversion from a string to an integer in order to create an average. I know to use the $convert in later versions, but I cannot find the correct place to use the $toInt term. I know the conversion using this keyword works on the command line on a single example, but where should I place this within the aggregate framework.
db.my_batch.aggregate([{"$unwind": "$current.Data.x"}, {"$match": {"current.Data.x.Typ": "01", "current.Data.x.Value": {"$lt": "TTTT"}}}, {"$project": {"current.Data.x.Value": 1, "uId":1}}, {"$group": {"_id": null, "ad": {"$avg": {"$toInt": "$current.Data.x.Value"}}}} ])
I get the following response:
2018-07-20T17:19:42.707+0200 E QUERY [thread1] Error: command failed: {
"ok" : 0,
"errmsg" : "Unrecognized expression '$toInt'",
"code" : 168,
"codeName" : "InvalidPipelineOperator"
} : aggregate failed :