tenantmongo)
tenant-mongo (nexttenant-mongo
, is a small layer on top of the mongodb native driver for node.js. It adds the following features
- All documents stored will get a
created
timestamp - All documents modified will get a
lastModified
timestamp - Multi tenancy: One collection can be split up into completely isolated documents for each tenant, while still only having one underlying physical MongoDB collection
- Safe deletion of documents (adding _deleted property instead of phisically remove document from collection)
Currently supported versions of MongoDB: 3.x, 4.x
Usage
Just include tenant-mongo
package instead of mongodb
const MongoClient ObjectID = ;
Configuration
You can specify current tenant options for db globaly or localy per collection
const client = await ; const dataBase = client; const collection1 = dataBase; // collection with global tenant const collection2 = dataBase; // collection with overrided tenant const collection3 = dataBase; // regular mongodb collection
Soft delete
tenant-mongo
soft deletes all documents. It just sets _deleted: new Date()
instead of deleting. And it adds _deleted: {$exists: false}
to all queries.
To bypass the softDelete on deleting or quering data you can do like this:
const client = await ; const dataBase = client; const collection1 = dataBase; // collection with 'hard' deletion mode collection1; //will find all documents including soft-deleted documents
Warning
Currently not supported default arguments for following collection method:
- find
- remove
- aggregate
so, if you going to skip query|selector or pipeline params it will not work correctly.