Skip to content

GermanMtzmx/mongoexample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example of mongodb CRUD api

Example of mongodb native driver for node js

Get started

npm install
npm start

fakeORM

Helpers to perform a crud in selected collection using native driver for mongodb in nodejs (all methods return a promise).

Methods

  • get: method that receives a collection name.

  • post: method that receives a collection name and request data.

  • put: method that receives a collection name, document id, and data.

  • delete: method that receives a collection name and an document id.

  • getById: method that receives a collection name and an document id.

Common use

Example of get method

  const fakeORM = require('./fakeORM');

  fakeORM.get('collectionName').then(response => {
    console.log(response)
  }).catch(error => {
    console.log(err)
  })

The promise always return an object like this :

 {
   code: 200 // status code for api by example 200,
   data: {...} // Object with data of operation
 }

Example with express route

app.get('/users', (req, res) => {
  fakeORM.get('users').then(
    result => {res.status(result.status).send(result.data);}
  ).catch(err => {
    res.status(err.status).send(err.data);
  });
});

About

Example of mongodb native driver for node js

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published