# mongo-native

> Native MongoDB API with promises just to make you happy

Latest version **1.0.28** (published 2015-07-17) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.28 |
| Published | 2015-07-17 |
| First published | 2015-05-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+7 in 2 direct dependencies) |
| Install scripts | no |
| Author | Victor Queiroz |
| Maintainers | victorqueiroz |

## Links

- npm: https://www.npmjs.com/package/mongo-native
- npm.io page: https://npm.io/package/mongo-native

## Dependencies (3)

- [q](https://npm.io/package/q.md) ^1.4.0
- [lodash](https://npm.io/package/lodash.md) ^3.8.0
- [mongodb](https://npm.io/package/mongodb.md) ^2.0.35

## Recent versions

- 1.0.28 (latest) — 2015-07-17
- 1.0.27 — 2015-07-14
- 1.0.26 — 2015-07-02
- 1.0.25 — 2015-07-02
- 1.0.24 — 2015-07-01
- 1.0.23 — 2015-06-30
- 1.0.22 — 2015-05-28
- 1.0.21 — 2015-05-17
- 1.0.2 — 2015-05-17
- 1.0.1 — 2015-05-15
- 1.0.0 — 2015-05-13

## README

# mongo-native

Native MongoDB API with promises just to make you happy.

We're just following the `mongodb` npm package api, which you can check [here](http://mongodb.github.io/node-mongodb-native/2.0/api/).

### Installation (npm)
```
npm install --save mongo-native
```

### Examples
```js
var MongoNative = require('mongo-native');

MongoNative.connect('mongodb://localhost/native-db').then(function (db) {
	var users = db.collection('users');

	users.insertMany([{name: 'kris kowal'}, {name: 'tj'}, {name: 'douglas crockford'}]).then(function (docs) {
		assert.equal('kris kowal', docs[0].name);
	});
});
```

```js
db.collection('users', function (err, users) {
	if(err) {
		throw err;
	}

	users.insertOne({name: 'addy osmani'}).then(function (user) {
		assert.equal('addy osmani', user.name);
	});
});
```

```js
var Db = require('mongo-native').Db;
var mongodb = require('mongodb');
var MongoClient = mongodb.MongoClient;

MongoClient.connect('mongodb://localhost/mydb', function (err, db) {
	if(err) {
		throw err;
	}

	global.db = new Db(db);
});

app.listen(3000, function () {
	console.log('Everything is cool now');
});
```

```js
var docs = [{
  title : "this is my title", author : "bob", posted : new Date() ,
  pageViews : 5, tags : [ "fun" , "good" , "fun" ], other : { foo : 5 },
  comments : [
    { author :"joe", text : "this is cool" }, { author :"sam", text : "this is bad" }
  ]}];

// Create a collection
var collection = db.collection('aggregationExample1');
// Insert the docs
collection.deleteMany({}, {w:1}).then(function () {
	return collection.insertMany(docs, {w: 1});
}).then(function(result) {
  // Execute aggregate, notice the pipeline is expressed as an Array
  var promise = collection.aggregate([
      { $project : {
        author : 1,
        tags : 1
      }},
      { $unwind : "$tags" },
      { $group : {
        _id : {tags : "$tags"},
        authors : { $addToSet : "$author" }
      }}
  ]);

  return promise;
}).then(function(result) {
  res.json(result);
}, function (err) {
	console.log(err);
	res.status(400).end();
});
```

```js
MongoNative.connect('mongodb://localhost/mydb').then(function (db) {
	var users = db.collection('users');
	return users.find();
}).then(function (users) {
	assert.equal(300000, users.length);
});
```

Do you mean... [More examples](https://github.com/VictorQueiroz/mongo-native/tree/master/test/unit)? o:

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