Skip to content

Instantly share code, notes, and snippets.

@sido
Created August 30, 2011 22:23
Show Gist options
  • Save sido/1182269 to your computer and use it in GitHub Desktop.
Save sido/1182269 to your computer and use it in GitHub Desktop.
Simple MongoDB Query in NodeJS using node-mongodb-native vs. node-mongoskin
var Db = require('../lib/mongodb').Db,
Connection = require('../lib/mongodb').Connection,
Server = require('../lib/mongodb').Server;
var host = 'localhost';
var port = Connection.DEFAULT_PORT;
var db = new Db('example', new Server(host, port, {}), {native_parser:true});
db.open(function(err, db) {
db.collection('docs', function(err, collection) {
collection.find(function(err, cursor) {
cursor.each(function(err, doc) {
if (doc === null) {
db.close();
}
console.dir(doc);
});
});
});
});
var mongo = require('mongoskin');
mongo.db('localhost:27017/example').collection('docs').find().toArray(function(err, docs){
console.dir(docs);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment