Newton's Principia Mathematica
    Have ideas to improve npm?Join in the discussion! »

    fastify-mongojs

    0.1.0 • Public • Published

    fastify-mongojs

    Simple wrapper around mongojs to share common connection pool across Fastify server. This project is experimental if you need something stable, take a look at fastify-mongodb

    js-standard-style Build Status Known Vulnerabilities Coverage Status

    Install

    $ npm i --save fastify-mongojs 
    

    Example

      const Fastify = require('fastify')
      const fastifyMongojs = require('fastify-mongojs')
      
      const fastify = Fastify()
     
      fastify.register(fastifyMongojs, { 
        name: 'myMongo',
        url: 'myDb',
        collections: ['awesome_collection']
      })
     
      fastify.get('/', function(req, reply) => {
        // You can reach the db connection with fastify.myMongo
      })
     
      fastify.listen(3000, err => {
        if (err) throw err
      })  

    Reference

    name type required default
    name {String} 'mongo'
    url {String} ✔️
    collections {Array} []

    The only plugin specific option is name which makes possible to share multiple connection pools across the server instance. The url and collections options will be passed to mongojs separately, all other options will be passed to the mongojs instance as well. For more information about the avaiable options please see mongojs.

    Caveats

    Due the recent changes in mongodb if you pass mongodb connection to mongojs it will fail. There is a PR in place which needs to be published first, to imlement this feature.

    License

    Licensed under MIT.

    Install

    npm i fastify-mongojs

    DownloadsWeekly Downloads

    0

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    8.22 kB

    Total Files

    6

    Last publish

    Collaborators

    • avatar