Query data and keep it in sync

I’m trying to make an abstract layer for caching documents in application. This cache would get a filter definition, start a collection.watch() and also query the database to pull all documents that match it.
(so I don’t have to write almost the same kind of code about 100 times).

But i’m not sure if i’m approaching this right.

  • Is there built-in functionality (int the driver) that would first query the data and then keep a watch() for changes done to any document that matches the filter, so that my cache can be updated?

  • If such functionality isn’t available, is there a way to apply the same filter both to the db.find() and collection.watch? The problem is, a filter for collection.watch() would need a prefix “fullDocument.” for every field… or perhaps is there a way to convert a “regular filter” used in collection.find(), into a changeStream filter?

  • How about using the C#-defined expressions for changeStream filtering? From what i see, the filter (that goes into the pipeline, which then goes into the collection.watch() ) can only be defined as a BsonDocument?

Thanks for your help!