I am currently receiving a mongo aggregate query from a payload:
[
{
"$match": {
"isComplete": true
"accountId": "foo123"
"startTime": "2017-03-06T23:07:21.262Z"
"$or": [ { userId: "bar123" }, { userId: "bar235" } ]
}
},
{
"$group": {
"_id": null,
"count": {
"$sum": 1
}
}
}
]
This is being stored as a map[string]interface{}
. The issue is the $match
clause can be any arbitrary query, which means it can contain ObjectIds and Dates. I have tried manually converting ids to bson.ObejectId
s and any Dates to time.Times
but the queries can become very complicated.
Does anyone know any good way of taking an arbitrary mongo query from a payload and converting it?