api-mongodb
v0.1.4
Published
MongoDB API wrapper
Downloads
4
Readme
api-mongodb
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-mongodb");
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 } | ✓
Tests
$ npm test
Mongo API
Methods
✓ insertDocument
✓ getDocumentByID
✓ searchCollectionsForDocumentWithID
✓ updateDocument
✓ deleteDocument
✓ createCollectionWithUniqueIndices
✓ createCollectionWithTemporaryDocuments
✓ done
8 passing (89ms)