keyv-mongodb

3.0.0 • Public • Published

keyv-mongodb

MongoDB storage adapter for Keyv with support for Mongoose

Installation

mongodb and mongoose are both peerDependecies. Install either one (or both) you'll be using with this package.

yarn add keyv keyv-mongodb mongoose
# or
yarn add keyv keyv-mongodb mongodb

Compatibility

Connection to MongoDB

Re-use a Mongoose connection

const mongoose = require('mongoose')

mongoose.connect(connectionOptions)

const keyv = new Keyv({
	store: new KeyvMongoDB({ mongooseConnection: mongoose.connection }),
})

Re-use a native MongoDB driver connection (or a promise)

const keyv = new Keyv({
	store: new KeyvMongoDB({ db: dbInstance }),
})

Or just give a promise...

const keyv = new Keyv({
	store: new KeyvMongoDB({ dbPromise: dbInstancePromise }),
})

Create a new connection from a MongoDB connection string

MongoDB connection strings are the best way to configure a new connection. For advanced usage, more options can be configured with mongoOptions property.

const keyv = new Keyv({
	store: new KeyvMongoDB({ url: 'mongodb://localhost/test-app' }),
})

License

ISC License

Based on work from

Package Sidebar

Install

npm i keyv-mongodb

Weekly Downloads

2,184

Version

3.0.0

License

ISC

Unpacked Size

6.31 kB

Total Files

3

Last publish

Collaborators

  • hendrysadrak