1.0.7 • Published 4 years ago

@ethiclab/crud-mongo v1.0.7

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

crud-mongo

npm install @ethiclab/crud-mongo

usage

A simple example, with no actual express router, only for testing purposes.

const crud = require("@ethiclab/crud-mongo");
(async () => {
  const controller = await crud({
    mongoUrl: 'mongodb://localhost',
    databaseName: 'sys',
    root: '/',
    router: {
      get: () => {
        return {}
      },
      post: () => {
        return {}
      },
      put: () => {
        return {}
      },
      delete: () => {
        return {}
      }
    },
    col: 'mycollection'
  })
  const x = await controller.create({
    name: 'test object'
  })
  console.log(x)
})()

An example using express router.

const express = require('express')
const app = express()
const router = express.Router()

crud({
    mongoUrl: 'mongodb://localhost',
    databaseName: 'sys',
    root: '/',
    router: router,
    col: 'mycollection'
})

app.use((req, res, next) => {
  router(req, res, next)
})

app.listen(12345)

Then, you can visit:

http://localhost:12345/mycollection

You can also use, for instance, Postman, for creating, updating and deleting records.

The following endpoints are defined:

GET /mycollection
POST /mycollection
GET /mycollection/:id
PUT /mycollection/:id
DELETE /mycollection/:id

where are the schemas?

This is a low level library for storing arbitrary documents with arbitrary properties in order to support new properties, therefore, we decided not to add schema support at this level.

test

docker run --name localmongo --rm -d -p 27017:27017 mongo
npm test
1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago