0.2.5 • Published 11 years ago

mongo-col v0.2.5

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

mongo-col Build Status

mongoDB collection wrapper

Status: production ready

Example

With mongo-db native

var Db = require('mongodb').Db,
    Server = require('mongodb').Server

var db = new Db('integration_tests', 
    new Server("127.0.0.1", 27017, {
       auto_reconnect: false, 
       poolSize: 4
    }))

db.open(function(err, db) {
    db.collection("CollectionName", function(err, collection) {
        collection.insert({hello:'world_no_safe'}, function () {
            collection.findOne({hello:'world_no_safe'}, function(err, item) {
                assert.equal(null, err)
                assert.equal('world_no_safe', item.hello)
                db.close()
            })
        })
    })
})

With mongo-col

var collection = require("mongo-col"),
    CollectionName = collection("CollectionName", "integration_tests")

CollectionName.insert({ hello: "world_no_safe"}, function () {
    CollectionName.findOne({ hello: "world_no_safe"}, function (err, item) {
        assert.equal(null, err)
        assert.equal('world_no_safe', item.hello)
        CollectionName.collection.db.close()
    })
})

Motivation

Setting up a mongodb database connection requires too much callback soup, remove it.

Documentation

collection(collectionName[, databaseName])

collection takes a collection name and returns a collection object. This collection object has all the mongodb collection methods and sets up a database connection internally

See the MongoDB collection API

var collection = require("mongo-col"),
    Users = collection("Users", "optionalDatabaseName")

Users.insert({
    name: "foo",
    password: "bar"
})

You can optionally pass in a databaseName as a string or an instance of a mongodb database object.

There is also an optional async API

require("mongo-col")("Users", function (collection) {
    ...  
})

Benchmarks

$ make bench

global native benchmark took  9332 53
mongoose benchmark took  22710 121
collection benchmark took  9851 56
mongoskin benchmark took  10817 59

Installation

npm install mongo-col

Tests

make test

Contributors

  • Raynos

MIT Licenced

0.2.5

11 years ago

0.2.4

11 years ago

0.2.3

11 years ago

1.0.5

12 years ago

1.0.4

12 years ago

1.0.1

12 years ago

1.0.0

12 years ago

0.2.2

12 years ago

0.2.1

12 years ago

0.2.0

12 years ago

0.1.17

12 years ago

0.1.16

12 years ago

0.1.15

12 years ago

0.1.14

12 years ago

0.1.13

12 years ago

0.1.12

12 years ago

0.1.11

12 years ago

0.1.10

12 years ago

0.1.9

12 years ago

0.1.8

12 years ago

0.1.7

12 years ago

0.1.6

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