api-mongo
v0.0.1
Published
MongoDB API wrapper
Downloads
2
Readme
api-mongo
A non-relational database wrapper for MongoDB
Requirements:
- mongodb 2.2.10
Getting started
Make sure your database is running and listening on port 27017. You can do that by running bash $ mongod
.
Once the database is running, and your configuration is in place, you can run this package:
$ npm install;
$ npm test;
$ npm start;
Basic usage
const MongoClient = require("api-mongo");
const url = 'mongodb://localhost:27017/test';
const mongo = new MongoClient(url);
let person = {};
person.givenName = 'Jose';
person.familyName = 'Barrios';
//Insert document to collection
mongo.insertDocument('people', data)
.then(res => {
//Do something with DB response
console.log(res);
})
.catch(err =>{
//Handle error response
console.error(err);
})
Public Methods
Operation | Parameters | Unit test ------------- | ------------- | -------------- insertDocument | collection:String, data:Object | ✓ getDocumentByID | id:ObjectID | ✓ updateDocument | collection:String, id:ObjectID, data:Object | ✓ deleteDocument | { collection:String, id:ObjectID } | ✓