easymongo

Simple interface for the MongoDB API

This project is maintained by meritt

easymongo

NPM version Build status Test coverage Dependency status devDependency status

This is a small tweaks for the native MongoDB driver.

Installation

$ npm install easymongo

Examples

var easymongo = require('easymongo');

var mongo = new easymongo({dbname: 'test'});
var users = mongo.collection('users');

var data = {name: 'Alexey', surname: 'Simonenko', url: 'http://simonenko.su'};
users.save(data, function(error, results) {
  // Returns a new document (array).
  console.log(results);
});

users.find({name: 'Alexey'}, {limit: 2}, function(error, results) {
  // Always return array of documents.
  console.log(results);
});

users.findById('4e4e1638c85e808431000003', function(error, results) {
  // Returns a document (object). If error occur then returns false.
  console.log(results);
});

users.count({name: 'Alexey'}, function(error, results) {
  // Amount (int). If error occur then returns zero.
  console.log(results);
});

users.remove({name: 'Alexey'}, function(error, results) {
  // Returns a result of operation (boolean). If error occur then returns false.
  console.log(results);
});

users.removeById('4e4e1638c85e808431000003', function(error, results) {
  // Returns a result of operation (boolean). If error occur then returns false.
  console.log(results);
});

API

Client class

Constructor

Arguments:

Methods

Collection class

Methods

Possible find options:

Flow control

You can use easymongo with co for generator based flow-control. For these purposes use the co-easymongo.

Contributing

DO NOT directly modify the lib files. These files are automatically built from CoffeeScript sources located under the src directory.

To do build run:

$ npm run build

Author

License

The MIT License, see the included license.md file.