Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
The easiest MongoDB API
JavaScript CoffeeScript

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
src
test
.gitignore
.npmignore
.travis.yml
Cakefile
license.md
package.json
readme.md

readme.md

Easiest mongodb

NPM version Build Status Coverage Status Dependency Status devDependency Status

This is a small extension for quick work with MongoDB native driver.

Installation

$ npm install easymongo

Examples

var Easymongo = require('easymongo');
var mongo = new Easymongo({dbname: 'test'});

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

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

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

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

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

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

API

Constructor

Arguments:

  • server (string || object) — connection url to MongoDB or object with host, port and dbname
  • options (object) — optional options for insert command

Methods

  • find (collection[, params][, options][, callback])
  • findById (collection, id[, callback])
  • save (collection, params[, callback])
  • remove (collection[, params][, callback])
  • removeById (collection, id[, callback])
  • count (collection[, params][, callback])
  • collection (collection, callback)
  • close ()

Author

License

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

Bitdeli Badge

Something went wrong with that request. Please try again.