I have a mongodb collection that I am trying to limit the result set, but the data was created by someone else and the date format appears to be stored as "2016-05-12 00:00:00.000Z". I am unsure how to format my find query to limit this type of date. I have been successful with other types of date formats, but not this one. Has anyone else encountered this issue?
myCollection {
"_id" : {
"$oid" : bson.ObjectId
},
"createdDate" : {
"$date" : Date
}
This is what I have attempted.
toDate := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.UTC)
fromDate := toDate.AddDate(0, 0, -1)
collectionResult := collectionRecords.Find(bson.M{"retailer": result.Id, "createdAt": bson.M{"$gte": fromDate}})
Ultimately, I would like to limit to one day and was attempting to do the following:
collectionResult := collectionRecords.Find(bson.M{"retailer": result.Id, "createdAt": bson.M{"$gte": fromDate, "$lt": toDate}})
collectionResult.All(&collectionData)
collectionCount, _ := collectionResult.Count()
fmt.Println("Count: ", collectionCount)
it always returns 0. Like I stated above I have been successful with UTC dates, but this one seems to trouble me.