Skip to content

Instantly share code, notes, and snippets.

@tobiassjosten
Created August 22, 2010 15:31
Show Gist options
  • Save tobiassjosten/543892 to your computer and use it in GitHub Desktop.
Save tobiassjosten/543892 to your computer and use it in GitHub Desktop.
var mongodb = require('mongodb');
var Db = mongodb.Db;
var Server = mongodb.Server;
module.exports = Database;
function Database(database_name, host, port) {
this.client = new Db(database_name, new Server(host, port, {}));
this.find = function(collection_name, params, callback) {
this.client.collection(collection_name, function(err, collection) {
collection.find(params, function(err, cursor) {
cursor.toArray(function(err, results) {
callback(results);
});
});
});
}
}
Database.prototype = new process.EventEmitter();
exports['connect'] = function(test){
test.expect(0);
var Database = require('database');
var database = new Database('ubertest', '127.0.0.1', 27017);
database.find('characters', {name:'Tobias'}, function(characters) {
console.log(require('sys').inspect('callback', true, null));
console.log(require('sys').inspect(characters, true, null));
});
test.done();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment