@events/snapshot-mongo

2.4.2 • Public • Published

@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
);

Readme

Keywords

none

Package Sidebar

Install

npm i @events/snapshot-mongo

Weekly Downloads

1

Version

2.4.2

License

ISC

Unpacked Size

205 kB

Total Files

31

Last publish

Collaborators

  • tungv