I have an application that uses a change stream to watch incoming information. However, there is a use case that pipeline of the change stream will be updated from other sources. I cannot predict the input, it is user related.
Is there a suggested way to update the pipeline for a change stream? I am using mongocxx. Mongocxx example is mostly welcomed, other language/general suggestions are also appreciated.
pipeline = [
{"$match": {"fullDocument.username": "alice"}},
{"$addFields": {"newField": "this is an added field!"}},
]
cursor = db.inventory.watch(pipeline=pipeline)
document = next(cursor)
The pipeline is part of the creation of the change stream itself, so I don’t think it can be modified once it’s created.
An alternative would be to get everything from the change stream (without any pipeline), pass the output to a second process that can filter it, then pass that output to the final destination. You can design the second process to have modifiable filters (which could be in any language).