@saurabharch/rollout-kvbasemongo

1.0.0 • Public • Published

npm version

Rollout key-value database adapter for MongoDB

This class uses a MongoDB collection as a very simple key-value storage. It only provides basic methods: set(), get(), remove()

Instance and connect

const kvbase_collection = 'kvstore';
MONGODB_URI = 'YOUR MONGODB CONNECTION URI';
const db = new KVBaseMongo(kvbase_collection);
db.connect(MONGODB_URI, () => {
  console.log("KVBaseMongo successfully connected.");
});

Set a value

let content = {
  name: "Andrew"
}
const CONTENT_KEY = 'YOUR CONTENT KEY'
await db.set(CONTENT_KEY, content)
console.log("Content saved")

Get a value

const content = await db.get(CONTENT_KEY);
console.log("Got content:", content)

## Remove a value

await db.remove(CONTENT_KEY);
console.log("Content deleted.");

Readme

Keywords

none

Package Sidebar

Install

npm i @saurabharch/rollout-kvbasemongo

Weekly Downloads

27

Version

1.0.0

License

MIT

Unpacked Size

4.34 kB

Total Files

4

Last publish

Collaborators

  • saurabharch