@modernpoacher/catbox-mongodb

MongoDB adapter for Catbox

Usage no npm install needed!

<script type="module">
  import modernpoacherCatboxMongodb from 'https://cdn.skypack.dev/@modernpoacher/catbox-mongodb';
</script>

README

@modernpoacher/catbox-mongodb

A MongoDB adapter for catbox.

@modernpoacher/catbox-mongodb serializes values to BSON using the MongoDB driver.

This adapter supports Object, Array, Number, String, Date, and RegExp data types.

Installation

Install @modernpoacher/catbox-mongodb via NPM.

@modernpoacher/catbox-mongodb requires catbox:

npm install catbox @modernpoacher/catbox-mongodb

Options

@modernpoacher/catbox-mongodb accepts the following options:

  • uri - the MongoDB URI, defaults to 'mongodb://127.0.0.1:27017/?maxPoolSize=5'
  • partition - the MongoDB database for cached items

Usage

Sample catbox cache initialization :

const Catbox = require('catbox');

const cache = new Catbox.Client(require('@modernpoacher/catbox-mongodb'), {
  uri: 'your-mongodb-uri', // Defaults to 'mongodb://127.0.0.1:27017/?maxPoolSize=5'
  partition: 'your-cache-partition'
})

Or configure your hapi server to use @modernpoacher/catbox-mongodb as the caching strategy.

For hapi v17:

const Hapi = require('hapi')

const server = new Hapi.Server({
  cache: [
    {
      name: 'mongodb-cache',
      engine: require('@modernpoacher/catbox-mongodb'),
      uri: 'your-mongodb-uri', // Defaults to 'mongodb://127.0.0.1:27017/?maxPoolSize=5'
      partition: 'your-cache-partition'
    }
  ]
})

For hapi v18:

const Hapi = require('hapi')

const server = new Hapi.Server({
  cache : [
    {
      name: 'mongodb-cache',
      provider: {
        constructor: require('@modernpoacher/catbox-mongodb'),
        options: {
          uri: 'your-mongodb-uri', // Defaults to 'mongodb://127.0.0.1:27017/?maxPoolSize=5'
          partition: 'your-cache-partition'
        }
      }
    }
  ]
})