MK5 Change streams with `watch` aggregate stage not working properly.
Andrewangeta opened this issue · comments
So in my app I'm opening a change stream but I want to filter changes based on a match
stage. I have the following
var options = ChangeStreamOptions()
options.fullDocument = ChangeNotificationType.updateLookup
let id = try ObjectId("blehblehbleh")
db["collection"].aggregate().match([:]).watch(withOptions: options).do { stream in
stream.forEach { notification in
if let doc = notification.fullDocument {
let model = try decoder.decode(MyModel.self, from: doc)
print(doc)
print(model)
}
}
}.catch { error in
print(error)
}
And with any changes to my collection I get back the document that was updated and that works fine.
if I change the aggregate() line to
db["collection"].aggregate().match(["_id": id]).watch(withOptions: options).do { stream in
I never get any notifications about the change in the collection.
I've even tried to match every specific field for one document and still no results. It only works when I don't provide any query for the match.
This makes me think that maybe the format isn't correct when sending over the wire. I'll attempt to try this in the mongo shell with Atlas to see if it works.
Was able to get this working by specifying the fullDocument
db["collection"].aggregate().match(["fullDocument._id": id]).watch(withOptions: options).do { stream in
Can this be closed?
Yep I think anything else is I run into is just lack of knowledge on it.