Skip to content

imCoding/easymongo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

easymongo

NPM version Build Status Coverage Status Dependency Status devDependency Status

This is a small tweaks for the native MongoDB driver.

Installation

$ npm install easymongo

Examples

var options = {
  dbname: 'test'
};

var mongo = new require('easymongo')(options);
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: 1}, 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:

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

Methods

  • collection (name) — returns a new instance of the easymongo Collection class
  • open (name[, callback]) — returns the MongoDB Collection
  • close — close the db connection

Collection class

Methods

  • find ([params][, options][, callback])
  • findById (oid[, callback])
  • save (params[, callback])
  • remove ([params][, callback])
  • removeById (oid[, callback])
  • count ([params][, callback])

Flow control

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

Author

License

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

Bitdeli Badge

About

The easiest MongoDB API

Resources

License

Stars

Watchers

Forks

Packages

No packages published