Skip to content

Instantly share code, notes, and snippets.

@ralphholzmann
Created July 7, 2011 16:23
Show Gist options
  • Save ralphholzmann/1069899 to your computer and use it in GitHub Desktop.
Save ralphholzmann/1069899 to your computer and use it in GitHub Desktop.
var db = new mongo.Db('myDB', new mongo.Server("localhost", "27017", {})),
to = "ralph";
db.open( function( err, p_client ) {
// Problem opening the database?
if ( err ) {
console.log( "db.open: " + err );
}
// Open the users collection
db.collection( 'users', function( err, collection ) {
// Retry if no collection was found
if ( err || ( ! "findOne" in collection )) {
console.log("db.collection: " + err );
} else {
// Let's find our user
collection.findOne({
"addresses.localPart" : to
}, function( err, doc ) {
if ( err ) {
console.log( "collection.findOne: " + err );
}
console.log( "doc: " + doc );
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment