0.1.0 • Published 6 years ago

fastify-mongojs v0.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

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

nametyperequireddefault
name{String}:x:'mongo'
url{String}:heavy_check_mark:
collections{Array}:x:[]

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.