DBH is a powerfull library for creating methods to work with MongoDB
I am using it myself in API for my site. It is very fast and simple to understand.
If you don't like to check every param from http requests, DBH has good instruments to check your params values and types. It will't able you to make mistake and save wrong data.
Also you can write your own errors names if you don't like DBH default error names
It using config params and creating methods from templates
npm i hm-dbh
initing module
const DB = {
login: "", // MongoDB User login
password: "", // MongoDB user password
host: "", // url to MongoDB server
database: "" // MongoDB database name
}
const options = {
// edit default DBH config values
}
const GEN = require("path to GEN file")
DBH.init(DB, options, GEN).then(() => {
// do something
})
example usage
// req.body.auth - jwt token
DBH.User.postJWT(req.body.auth).then(user => {
DBH.User.login(user).then(User => {
User.name = "John"
User.surname = "Doe"
User.save()
// ...
see ./example/gen.example.js