0.1.6 • Published 11 years ago

mongode v0.1.6

Weekly downloads
4
License
-
Repository
github
Last release
11 years ago

Introduction

Mongode is a very thin (~200 lines of code) wrapper around the node-mongodb-native driver. It buffers collection operations until a connection is made, thus removing one level of callback nesting. It also binds collections to the database object as a key on the object making code easier to read. See below for examples of how to insert a document using mongode and how to bind collections.

Installation

npm install mongode

Examples

Insert

node-mongodb-native:

var mongodb = require('mongodb');
var server = new mongodb.Server("127.0.0.1", 27017, {});
new mongodb.Db('test', server, {}).open(function (error, client) {
  if (error) throw error;
  var collection = new mongodb.Collection(client, 'test_collection');
  collection.insert({hello: 'world'}, {safe:true}, function(err, objects) {
    if (err) console.warn(err.message);
  });
});    

mongode:

var mongode = require('mongode');
var test = mongode.connect('mongo://127.0.0.1/test');
var collection = test.collection('test_collection');
collection.insert({hello: 'world'}, {safe:true}, function(err, objects) {
  if (err) console.warn(err.message);
});

Binding

You can bind databases and collections by name:

var mongode = require('mongode');
mongode.connect('mongo://127.0.0.1/test');

var test = mongode.test;
test.collection('foo');
test.collection('bar');

test.foo.find().each(function(err, object) {});
test.bar.find().each(function(err, object) {});
0.1.6

11 years ago

0.1.5

11 years ago

0.1.4

12 years ago

0.1.3

12 years ago

0.1.2

12 years ago

0.1.1

12 years ago

0.1.0

12 years ago

0.0.12

12 years ago

0.0.11

12 years ago

0.0.10

12 years ago

0.0.9

13 years ago

0.0.8

13 years ago

0.0.7

13 years ago

0.0.6

13 years ago

0.0.5

13 years ago

0.0.4

13 years ago

0.0.3

13 years ago

0.0.2

13 years ago

0.0.1

13 years ago