I'm trying to create an aggregate pipeline using the Mgo driver. I keep running into the unknown top level operator $not issue for the following setup. I'm a beginner at using go and mongo. I'm creating this pipeline to filter out users that don't match a certain criteria such as that they are active. Is there any easier way to accomplish this?
today := time.Now()
pipe2 := bson.M{"$match": bson.M{
"$not": []bson.M{
bson.M{StartDate: bson.M{"$gte": today}},
bson.M{EndDate: bson.M{"$lte": today}}}}}
$not
takes an object, not an array:
https://docs.mongodb.com/manual/reference/operator/query/not/
You have you change your query:
bson.M{"$match":
bson.M{StartDate:
bson.M{"$not": bson.M{"$gte": today, "$lte": today}}}}