
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@uscreen.de/fastify-mongo-crud
Advanced tools
Tiny mongodb decorator providing CRUD-style DB-methods
$ yarn add @uscreen.de/fastify-mongo-crud
Adding @uscreen.de/fastify-mongo-crud also adds fastify-mongodb as direct dependency.
Note: You still need to register
mongodbprior tocrudas seen in example below. This is due to encapsulation of fastify plugins assuming you will want to resuse samefastify.mongoaccross your application.
Setup within a plugins/mongo.js file:
'use strict'
const fp = require('fastify-plugin')
const mongodb = require('fastify-mongodb')
const crud = require('@uscreen.de/fastify-mongo-crud')
module.exports = fp((fastify, opts, next) => {
/**
* 1) setup mongodb connection
*/
fastify.register(mongodb, { url: opts.mongoUri })
/**
* 2) setup CRUD factory
*/
fastify.register(crud)
/**
* 3) proceed
*/
next()
})
Usage within a services/accounts.js file:
'use strict'
/**
* let's write a classic CRUD service
*/
module.exports = (fastify, opts, next) => {
const accounts = fastify.crud('accounts')
/**
* plug in some appropiate authentication
* middleware - of course!
*
* plus: add schemas to routes.
*/
/**
* create
*/
fastify.post('/accounts', async (req) => {
return { account: await accounts.create(req.body) }
})
/**
* read
*/
fastify.get('/accounts/:id', async (req) => {
return { account: await accounts.read(req.params.id) }
})
/**
* update
*/
fastify.put('/accounts/:id', async (req) => {
return { account: await accounts.update(req.params.id, req.body) }
})
/**
* delete
*/
fastify.delete('/accounts/:id', async (req) => {
return { account: await accounts.delete(req.params.id) }
})
/**
* list
*/
fastify.get('/accounts', async () => {
return { accounts: await accounts.list() }
})
next()
}
fastify.mongo from within this module, if not installed in parentLicensed under MIT.
Published, Supported and Sponsored by u|screen
FAQs
Tiny mongodb decorator providing CRUD-style DB-methods
We found that @uscreen.de/fastify-mongo-crud demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.