npm.io
1.0.0 • Published 7 years ago

mongodb-keyval-storage

Licence
MIT
Version
1.0.0
Deps
3
Size
10 kB
Vulns
0
Weekly
0
Stars
2

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')

Keywords