catbox-mongodb
MongoDB adapter for catbox
Lead Maintainer: Marcus Poehls
catbox-mongodb serializes values to BSON using MongoDB driver, therefore following data types are supported for this adapter: Object, Array, Number, String, Date, RegExp.
Installation
Install catbox-mongodb
via NPM. Remember that catbox-mongodb
requires its parent module catbox
:
npm install catbox catbox-mongodb
Options
catbox-mongodb
accepts the following options:
uri
- the MongoDB URI, defaults to'mongodb://127.0.0.1:27017/?maxPoolSize=5'
partition
- the MongoDB server database
Usage
Sample catbox cache initialization :
const Catbox = require('catbox');
const cache = new Catbox.Client(require('catbox-mongodb'), {
uri: 'your-mongodb-uri', // Defaults to 'mongodb://127.0.0.1:27017/?maxPoolSize=5' if not provided
partition: 'cache'
})
Or configure your hapi server to use catbox-mongodb
as the caching strategy (code snippet uses hapi v17
):
const Hapi = require('hapi')
const CatboxMongoDB = require('catbox-mongodb')
const server = new Hapi.Server({
cache : [{
name : 'mongoDbCache',
engine : CatboxMongoDB,
uri : 'your-mongodb-uri', // Defaults to 'mongodb://127.0.0.1:27017/?maxPoolSize=5' if not provided
partition : 'cache'
}]
});