Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hendrysadrak/keyv-mongodb
MongoDB storage adapter for Keyv with support for Mongoose
https://github.com/hendrysadrak/keyv-mongodb
javascript keyv mongodb mongodb-storage-adapter mongoose
Last synced: 4 days ago
JSON representation
MongoDB storage adapter for Keyv with support for Mongoose
- Host: GitHub
- URL: https://github.com/hendrysadrak/keyv-mongodb
- Owner: hendrysadrak
- Created: 2018-12-03T12:51:57.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-02-04T06:04:20.000Z (almost 2 years ago)
- Last Synced: 2024-11-08T04:50:01.656Z (7 days ago)
- Topics: javascript, keyv, mongodb, mongodb-storage-adapter, mongoose
- Language: JavaScript
- Homepage: https://npm.im/keyv-mongodb
- Size: 17.1 MB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# 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.
```bash
yarn add keyv keyv-mongodb mongoose
# or
yarn add keyv keyv-mongodb mongodb
```## Compatibility
- Support [Mongoose](http://mongoosejs.com/index.html) `>= 6`
- Support [native MongoDB driver](http://mongodb.github.io/node-mongodb-native/) `>= 4`
- Support Node.js >=10### Connection to MongoDB
#### Re-use a Mongoose connection
```js
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)
```js
const keyv = new Keyv({
store: new KeyvMongoDB({ db: dbInstance }),
})
```Or just give a promise...
```js
const keyv = new Keyv({
store: new KeyvMongoDB({ dbPromise: dbInstancePromise }),
})
```#### Create a new connection from a MongoDB connection string
[MongoDB connection strings](http://docs.mongodb.org/manual/reference/connection-string/) are **the best way** to configure a new connection. For advanced usage, [more options](http://mongodb.github.io/node-mongodb-native/driver-articles/mongoclient.html#mongoclient-connect-options) can be configured with `mongoOptions` property.
```js
const keyv = new Keyv({
store: new KeyvMongoDB({ url: 'mongodb://localhost/test-app' }),
})
```## License
ISC License
Based on work from
- https://github.com/jdesboeufs/connect-mongo
- https://github.com/lukechilds/keyv-mongo