I am trying to create a mongodb "Change Stream" on collection and listen to changes on a specific document.
matchID := bson.D{
{"$match", bson.M{"_id": tid}},
}
stream, err := collection.Watch(ctx, mongo.Pipeline{matchID}, options.ChangeStream().SetFullDocument(options.UpdateLookup))
Then listen on the stream with a for loop.
for stream.Next(ctx) {
log.Println("stream.Next")
if err = stream.Decode(&event); err != nil {
log.Printf("error decoding: %s", err)
}
log.Printf("change event: %v", event)
publisher.NotifyEvent(event["fullDocument"])
}
The whole setup works when I remove the pipeline argument, and I start getting data in loop. But when I add the pipeline filter, it stops working.