@events/snapshot-mongo

query/mutate mongo db snapshot for @events/subscriber-cli

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
@events/snapshot-mongo
Minified + gzip package size for @events/snapshot-mongo in KB

Readme

@events/snapshot-mongo

This package receives a stream of commands, converts them to mongodb commands and persists them to a mongodb database. It also takes care of optimistic locking to ensure data consistency.

API

  1. version(config: PersistenceConfig, collections: CollectionMeta[]): Promise<SnapshotVersionMeta>
const { persist, version } = require('@events/snapshot-mongo');

const persistenceConfig = {
  store: 'mongodb://localhost/my_example_db',
};

const interestedCollections = [
  { name: 'users', version: '1.0.0' },
  { name: 'users', version: '2.0.0' },
  { name: 'posts', version: '1.0.0' },
  { name: 'posts', version: '1.2.0' },
];

// get the latest snapshot version from mongodb://localhost/my_example_db
const snapshotMeta = await version(persistenceConfig, interestedCollections);

const { snapshotVersion } = snapshotMeta;

console.log(snapshotVersion) // logs: 5
  1. persists
const storeConfig = {
  _: ['mongodb://localhost/my_example_db']
}

const interestedCollections = [
  { name: 'users', version: '1.0.0' },
  { name: 'users', version: '2.0.0' },
  { name: 'posts', version: '1.0.0' },
  { name: 'posts', version: '1.2.0' },
];

// create a persistence stream from a projection stream
const persistence$ = await persist(
  storeConfig,
  projection$,
  interestedCollections
);

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.