I’m having trouble finding any examples of how I would go about using date in aggregation functions.
My go strut looks like this when converting the JSON to go.
type TcoIndexedSpans struct { ID string json:"_id" bson:"_id" ClientID string json:"clientID" bson:"clientID" IndexedSpanstUsageCost []struct { Date struct { NumberLong string json:"$numberLong" bson:"numberLong" } json:"$date" bson:"$date" IndexedSpansCost struct { NumberDouble float64 json:"$numberDouble" bson:"$numberDouble" } json:"IndexedSpansCost" bson:"IndexedSpansCost" IndexedSpansCount struct { NumberDouble float64 json:"$numberDouble" bson:"$numberDouble" } json:"IndexedSpansCount" bson:"IndexedSpansCount" } json:"IndexedSpanstUsageCost" bson:"IndexedSpanstUsageCost" }
This works in mongoplayground, but does not work when I put this in go using bson.
`matchStage := bson.D{{"$match", bson.D{{"IndexedLogsUsageCost.date", bson.D{{"$gt", 1661990400000}}}}}}
cursor, err := collection.Aggregate(context.TODO(), mongo.Pipeline{matchStage})
//cursor, err := collection.Aggregate(context.TODO(), mongo.Pipeline{matchStage, unwind, matchAgain})
if err != nil {
panic(err)
}`
How would I write that aggregate collection in the go driver correctly?