Looking at using mongoose to build a multi tenant application with logical separation using a tenant_id field in every document/table.
I am looking for a way to prefix a filter for tenant_id so that I always work with the filtered set (subset belonging to that particular tenant) of documents. Something along the lines of "pre" hook in which I can list the action and perform some additional steps. Any / Every interaction with the mongo db should be filtered automatically by this filter/scope.
Idea is that I dont want to add explicit filter for tenant_id into each & every mongoose calls in the code and what this filter to be implicit.
Can someone help/guide me towards how to achieve this?
Thanks