Under the hood mongoose ODM is used, the options that you pass to register
will be passed to the Mongoose connection. Pass the uri option is required.
npm i fastify-mongoose2 --save
Add it to you project with register
and you are done!
You can access the Mongoose Connection via fastify.mongo.db
and ObjectId via fastify.mongo.ObjectId
.
const fastify = require('fastify')
fastify.register(require('fastify-mongoose'), {
uri: 'mongodb://localhost/test_db'
})
fastify.listen(3000, err => {
if (err) throw err
console.log(`server listening on ${fastify.server.address().port}`)
})
"version": "0.3.0
and above plugin have ability to open connection with multiple different databases, for achieving this functionality it have to stop using default mongoose connection. Onward please use db client returned by this plugin.
Licensed under MIT.