@modernpoacher/catbox-mongodb

    1.0.11 • Public • Published

    @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'
            }
          }
        }
      ]
    })

    Install

    npm i @modernpoacher/catbox-mongodb

    DownloadsWeekly Downloads

    60

    Version

    1.0.11

    License

    BSD-3-Clause

    Unpacked Size

    41.2 kB

    Total Files

    7

    Last publish

    Collaborators

    • jonathanperry
    • modernpoacherlimited