@marcusgsta/mongodb-api
Connect to mongodb and perform CRUD-operations
Last updated 2 years ago by marcusgsta .
ISC · Original npm · Tarball · package.json
$ cnpm install @marcusgsta/mongodb-api 
SYNC missed versions from official npm registry.

Build Status Scrutinizer Code Quality Code Coverage Build Status

@marcusgsta/mongodb-api

Connect to Mongodb and use a simple API with Create, Read, Update and Delete routes.

This module is not recommended for using as is - it was created for educational purpose.

Install:

npm install @marcusgsta/mongodb-api

The api contains the following self-explanatory methods:

findInCollection(colName, criteria, projection, limit)
addToCollection(colName, item)
removeFromCollection(colName, id)
updateItemFromCollection(colName, id, item)
resetCollection(colName, doc)

There are example routes in /api, using the Express router module.

Use api as following:

Set your Mongodb dsn:

let Api = require('@marcusgsta/mongodb-api');

let api = new Api(process.env.DBWEBB_DSN || "mongodb://localhost:27017/math");

Create a collection:

let colName = "formulas";

READ

Example from /api using async await

router.get("/", async (request, response) => {

    try {
        let res = await api.findInCollection(colName, {}, {}, 0);
        response.json(res);
    } catch (err) {
        response.json(err);
    }
});

ADD

Create an object with the fields and values that you need.

let resObject = {
    "name": name,
    "formula": formula,
    "description": description
};

let res = await api.addToCollection("formulas", resObject);

You of course need Mongodb.

As an alternative you can install Docker according to your operative system: https://docs.docker.com/engine/installation/#server

Download mongodbs Docker image

docker pull mongo

Run mongodb

docker -up mongodb

Reset database and fill with default data

npm run reset-database

Current Tags

  • 1.1.0                                ...           latest (2 years ago)

10 Versions

  • 1.1.0                                ...           2 years ago
  • 1.0.9                                ...           2 years ago
  • 1.0.8                                ...           2 years ago
  • 1.0.7                                ...           2 years ago
  • 1.0.6                                ...           2 years ago
  • 1.0.5                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 3
Last Day 1
Last Week 0
Last Month 5
Dependencies (4)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |