1.0.0 • Published 5 years ago

mongodb-keyval-storage v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

mongodb-keyval-storage

Key Value Storage for MongoDB with a simple API

Build Status Coverage Status

Installation

npm install mongodb-keyval-storage

Usage

Configure Strategy

The MongoStorage constructor receives two parameters:

  • db: A MongoDB database connection or a connection string.
  • collectionName: The name of the collection used to save the data.

      const storage = new MongoStorage({
        db: 'mongodb://localhost:27017/db',
        collectionName: 'myCollection'
      })

API

Set

Adds a value with it's respective key to the database. Returns a promise.

await storage.set('key', 'value')

Get

Returns promise that resolves to a value given it's respective key.

const value = await storage.get('key')

Delete

Removes the key and value from the database, given the key. Returns a promise.

await storage.delete('key')