I've got a collection with a Date field:
{
"_id" : ObjectId("5b92b359ddceef5b24502834"),
"dateTimeGMT" : ISODate("2018-08-22T09:29:25.000Z"),
yada, yada, yada
}
I'm trying to find by date in a $match aggregation stage with the ParseExtJSONArray function of mongo-go-driver. (I am aware of how to do this with *bson.Array directly. I'm asking so I know the right way to do it with ParserExtJSONArray or if I've run up against a limitation.)
I've simplified to this example and confirmed it is failing to match the above document.
pipeline, err := bson.ParseExtJSONArray(`[
{ "$match": { "dateTimeGMT.$date":"2018-08-22T09:29:25.000Z" } }
]`)
cursor, err := receivedFromResponseQueue.Aggregate(ctx, pipeline)
The following doesn't work in the mongo shell. ( Not surprising because it converts automatically to ISODate() format )
db.getCollection('received_from_response_queue').aggregate([
{ "$match": { "dateTimeGMT.$date":"2018-08-22T09:29:25.000Z" } }
])
But this does work in the mongo shell.
db.getCollection('received_from_response_queue').aggregate([
{ "$match": { "dateTimeGMT": ISODate("2018-08-22T09:29:25.000Z") } }
])
But this returns an empty array in "pipeline". (Because ParseExtJSONArray doesn't handle JavaScript)
pipeline, err := bson.ParseExtJSONArray(`[
{ "$match": { "dateTimeGMT":ISODate("2018-08-22T09:29:25.000Z") } }
]`)
Because it then uses an empty array it retuns all the documents in the collection. Interestingly, the date is formatted differently in the document we are trying to match.
{
"_id" : { "$oid" : "5b92b359ddceef5b24502834" },
"dateTimeGMT" : { "$date" : "2018-08-22T05:29:25-04:00" },
yada yada yada
}
But this doesn't match either.
pipeline, err := bson.ParseExtJSONArray(`[
{ "$match": { "dateTimeGMT.$date":"2018-08-22T05:29:25-04:00" } }
]`)
cursor, err := receivedFromResponseQueue.Aggregate(ctx, pipeline)
And this doesn't work in the mongo shell.
db.getCollection('received_from_response_queue').aggregate([
{ "$match": { "dateTimeGMT.$date":"2018-08-22T05:29:25-04:00" } }
])
Any insight?