mongo-easy.js
Making the use of MongoDB very simple.
Implementation Requirements
- [NodeJS] node-requirements
- [MongoDB] mongodb-requirements
and your ready to go...
Implementation
Terminal
$ npm install mongo-easy --save
Javascript file
var mgo = ;
Get an array of users
Create an object to hold the collection name, projection and query
var param = collection: "registered" query: "firstname": 1 "lastname": 1 "email": 1 "_id": 0 projection: {}
And simply call the following function and pass your param
object into the getRecordArray
function
mgo
The above construct does two things:
- connects to the database.
- uses the connection to retrieve a required set of data
Other examples are : Get an array of records/documents returned one at a time.
mgo
Get a single record/document
mgo
Insert a record/document
//create an object to insert into functionvar userObj = collection: "registered" record: "firstname": "Bob" "lastname": "Bar" "email": "bob@someplace.com" mgo;
Edit configuration: Simply change the port or host.
// /config/dbConfig.jsvar config = moduleexports = mdb: "mongodb://" mhost: "127.0.0.1" mport: ":27017/";