/mongodb-versioner

Primary LanguageTypeScriptApache License 2.0Apache-2.0

mongodb-versionr

Requirements

MongoDB instances are required to have a Replica Set enable to allow Change Streams invocation. A quick tutorial to enable this can be found here.

Usage

Setup

const { MongoClient } = require("mongodb");
const versionr = require('mongodb-versionr');

const uri = "<your_mongo_client_uri>";
const client = new MongoClient(uri);

vnrContext = versionr.setContext(client);

Registering a model listener

vnrContext.registerModel({
    collection_name: "<your_collection>",
    database_name: "<your_database>",
    version_control_database_name: "<your_versioning_collection>",
    version_control_collection_name: "<your_versioning_collection>",
    keys: {
        "key1": "value1"
        ...
    }
});

If version_control_database_name is not provided, then database_name is set as the version control database.

Terminate all registered listeners

vnrContext.stopListeners();