jinwookie-mongodb-crud
v1.0.4
Published
mongodb CRUD package to create routes and data layer
Maintainers
Readme
jinwookie-crud-router
Package to create CRUD routes on express. Also, create a CRUD data layer, and execute queries in mongodb.
Installation
npm install jinwookie-crud-routerUsage
executeQuery
executes queries in the function passed in. Automatically will open connection before queries are executed, and then close the connection after queries executed.
function executeQuery(func)Parameters
func: (db) => Promise<result>
db: mongodb db object
Crud
CRUD data layer for mongodb
function crud(options) => {
insert,
select,
selectOne,
updateOne,
deleteOne,
}options
tableName: Name of mongodb table
fields: Object model
[
{
column: string
type: 'string' | 'number' | 'boolean' | 'ObjectId' | 'any'
key: boolean
}
...
]queries?: parameters used to query table
[
{
column: string
type: 'string' | 'number' | 'boolean' | 'ObjectId' | 'any'
}
]selectFunc?: additional mongodb pipeline for find
(pipeline) => <additional pipeline>selectOneFunc?: additional mongodb pipeline for retrieving single record
(pipeline) => <additional pipeline>CrudRouter
Creates an express router to handle CRUD methods
function crudRouter(options) => Routeroptions
crud: Crud data object
model?: function to set model for POST/PUT
(req: Request) => objectdefaults to req.body
select?: function to return select object for GET
(req: Request) => objectdefaults to { ...req.params, ...req.query }
Environment Variables
DB_CONN=mongodb+srv://{username}:<PASSWORD>@{cluster}?retryWrites=true
DB_NAME={dbname}
DB_PASSWORD={dbpassword}