mongodb-crud-router v1.1.0
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
createCrudRouter
CRUD data layer for mongodb
function createCrudRouter(options) => {
insertOne,
select,
selectOne,
updateOne,
deleteOne,
}options
tableName: string
Name of mongodb table
model: object
Object model
[
{
column: string
type: 'string' | 'number' | 'boolean' | 'ObjectId' | 'any'
key: boolean
}
...
]mergeParams: boolean
mergeParams parameter used for Router. Defaults to true.
useObjectId: boolean
use MongoDB generated ObjectId. Defaults to true.
idField: string
route id field. Defaults to id
customRoutes: Routes[]
Inject custom routes
appendParams: (req, res) => {object}
Function to add additional params
appendBody: (req, res) => {object}
Function to add additional data to the body
aggregate: object
Return MongoDB aggregate
Environment Variables
DB_CONN=mongodb+srv://{username}:<PASSWORD>@{cluster}?retryWrites=true
DB_NAME={dbname}
DB_PASSWORD={dbpassword}Development
npm run devRun in development mode using nodemon
Production
npm startRun in production mode