Created
August 30, 2011 22:23
-
-
Save sido/1182269 to your computer and use it in GitHub Desktop.
Simple MongoDB Query in NodeJS using node-mongodb-native vs. node-mongoskin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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