Created
August 6, 2014 09:37
-
-
Save flipjs/121599cbe8834fb44cd7 to your computer and use it in GitHub Desktop.
MongoDB and NodeJS
This file contains 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('mongodb') | |
var Server = mongo.Server | |
, Db = mongo.Db | |
, BSON = mongo.BSONPure | |
var server = new Server('localhost', 27017, {auto_reconnect: true}) | |
, db = new Db('dbName', server) | |
db.open(function(err, db) { | |
if (!err) { | |
console.log('Connected to "dbName" database') | |
db.collection('collName', {strict: true}, function(err, collection) { | |
if (err) { | |
// if collName collection does not exist, | |
// do something about it here (i.e, recreate one, return err, etc.) | |
} | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment