poseidon-mongo v0.5.0
Poseidon Mongo
Poseidon Mongo provides a promise layer around the Node Native MongoDB driver with the help of the Poseidon library.
It has performance on par with the plain mongodb native library
Native MongoDB x 277 ops/sec ±2.42% (80 runs sampled)
Poseidon MongoDB x 271 ops/sec ±2.65% (71 runs sampled)
Fastest is Native MongoDB,Poseidon MongoDBInstall
To get started simply run
npm install poseidon-mongoIntroduction
Compare the example below to the original introduction for the Node MongoDB Native Driver.
Javascript
Mongo = require('../index.js');
Driver = new Mongo.Driver();
Database = Mongo.Database;
assert = require('assert');
Driver.configure('test', { hosts: ['127.0.0.1:27017'], database: 'test', options: { w: 1 } });
client = new Database(Driver, 'test');
client.collection('test_insert')
.then(function(collection){
return collection.insert({a:2})
.then(function(docs){
return collection.count();
}).then(function(count){
assert(count, 1);
return collection.find();
}).then(function(cursor){
return cursor.toArray();
}).then(function(results){
assert(results.length, 1);
assert(results[0].a, 2);
})
}).finally(function(){
client.close();
}).done();Coffeescript
It get even better with Jeremy Ashkenas' Coffescript.
Mongo = require '../index'
Driver = new Mongo.Driver()
{Database} = Mongo
assert = require 'assert'
Driver.configure('test', { hosts: ['127.0.0.1:27017'], database: 'test', options: { w: 1 } })
client = new Database(Driver, 'test')
client.collection('test_insert')
.then (collection) ->
collection.insert({a:2})
.then (docs) ->
collection.count()
.then (count) ->
assert(count, 1);
collection.find()
.then (cursor) ->
cursor.toArray();
.then (results) ->
assert(results.length, 1);
assert(results[0].a, 2);
.finally () ->
client.close()
.done()API
The API for poseidon Mongo contains the complete API for the Node MongoDB Native driver's Db, Collection and Cursor classes.
Driver
The driver class provides for a easy management and configuration of databases through your entire application.
Driver.configure(connection, configuration)
Configures a connection using the given configuration. The possible configuration parameters are given below:
| Parameter | Description |
|---|---|
| auth | An authorization string of the format <user>:<pass>. Eg: 'foo:bar' |
| database | The database name |
| hosts | An array of hosts to which you wish to connect |
| options | Any additional options. Find the full list of options here |
Driver.openConnection(connection)
Open a previously configured connection and cache it for future reuse.
Driver.closeConnection(connection)
Close a connection and remove it from the cache.
Driver.reset()
Close all open connections and delete all configurations.
Database
The following functions are available. For detailed interface information check the Node MongoDB Native Documentation
addUserauthenticateclosecollectioncollectionNamescollectionscollectionsInfocommandcreateCollectioncreateIndexcursorInfodbdereferencedropCollectiondropDatabasedropIndexensureIndexevalindexInformationlastErrorlogoutpreviousErrorsreIndexremoveUserrenameCollectionresetErrorHistorystats
Collection
The following functions are available. For detailed interface information check the Node MongoDB Native Documentation
aggregatecountcreateIndexdistinctdropdropAllIndexesdropIndexensureIndexfindfindAndModifyfindAndRemovefindOnegeoHaystackSearchgeoNeargroupindexesindexExistsindexInformationinsertisCappedmapReduceoptionsreIndexremoverenamesavestatsupdate
Cursor
The following functions are available. For detailed interface information check the Node MongoDB Native Documentation
batchSizeclosecounteachexplainisClosedlimitnextObjectrewindsetReadPreferenceskipsortstreamtoArray
MongoDB Data Types
The following Data Types from the Node MongoDB Native driver are available:
BSONObjectIDBinaryCodeDoubleLongTimestampMaxKeySymbol
License
Copyright(c) 2013-2014, Playlyfe Technologies, developers@playlyfe.com, http://dev.playlyfe.com/