Default Query filter in the driver

Hi there
We would like to use the new driver for golang, and one of our needs is to have apply a default filter to a query before the actual find\etc functions are being used.
for instance if a developer would like to create some custom query, once the query is evaluated, the driver will add the default query (i.e. $and:[{email:โ€œxโ€}, userQuery]) to it.

Is this something possible to do? or for this to happen we must use a wrapper code that enforces it?
Thanks :slight_smile:

Hello @Oded_Valtzer, welcome to the MongoDB Community forum.

You can create a View on a collection - and on this view you can apply other queries.

While creating the view is easy, it has some restrictions. The documentation I had linked has all the details, but from the definition:

  • A MongoDB view is a queryable object whose contents are defined by an aggregation pipeline on other collections or views.
  • MongoDB does not persist the view contents to disk. A viewโ€™s content is computed on-demand when a client queries the view.
  • MongoDB can require clients to have permission to query the view.
  • MongoDB does not support write operations against views.