# mongo-easy

> Simple mongodb adapter

Latest version **0.0.3** (published 2015-09-11) · 0 weekly downloads

## Install

```sh
npm install mongo-easy
pnpm add mongo-easy
yarn add mongo-easy
bun add mongo-easy
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2015-09-11 |
| First published | 2015-09-11 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Mark O Grady |
| Maintainers | markogrady1 |

## Links

- npm: https://www.npmjs.com/package/mongo-easy
- Repository: https://github.com/markogrady1/mongo-easy
- Homepage: https://github.com/markogrady1/mongo-easy#readme
- Issues: https://github.com/markogrady1/mongo-easy/issues
- npm.io page: https://npm.io/package/mongo-easy

## Dependencies (2)

- [mongodb](https://npm.io/package/mongodb.md) ^2.0.26
- [underscore](https://npm.io/package/underscore.md) ^1.8.3

## Recent versions

- 0.0.3 (latest) — 2015-09-11
- 0.0.2 — 2015-09-11

## README

#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   
```bash
$ npm install mongo-easy --save
```
Javascript file
```javascript
var mgo = require('mongo-easy');


```

Get an array of users  
Create an object to hold the collection name, projection and query

```javascript
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

```javascript
mgo.getConnection('users',  function(db) {
	mgo.getRecordArray(db, param, function(doc) {
		console.log(doc);
	});
})
```
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.
```javascript
mgo.getConnection('users',  function(db) {
	mgo.getEachRecord(db, param, function(doc) {
	  console.log(doc);
 	});
})
```
Get a single record/document
```javascript
mgo.getConnection('users', function(db) {
 	mgo.getOneRecord(db, param, function(doc) {
 		console.log(doc);
 	});
})
```

Insert a record/document
```javascript
//create an object to insert into function
var userObj = {
	collection: "registered",
	record: { 
		"firstname": "Bob",
		"lastname": "Bar",
		"email": "bob@someplace.com"
	}
}

mgo.getConnection('users',  function(db) {
  mgo.insertOneRecord(db, userObj, function(result) {
 	  console.log(result);
  })
});
```

Edit configuration:
Simply change the port or host.

```javascript
//  /config/dbConfig.js
var config = module.exports = {
	mdb: "mongodb://",
	mhost: "127.0.0.1",
	mport: ":27017/"
};
```
[requirements]: https://github.com/jquery/content/issues/4  
[node-requirements]: https://nodejs.org/
[mongodb-requirements]: https://www.mongodb.org/
[npm-requirements]: https://docs.npmjs.com/getting-started/installing-node
[homebrew-requirements]: http://brew.sh/

---
_Source: https://npm.io/package/mongo-easy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
