-
-
Save tooshel/9996392 to your computer and use it in GitHub Desktop.
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').MongoClient; | |
var settings = { mongo: "mongodb://cactuscon:Wish2PacWasAlive23423524545234@ds029630.mongolab.com:29630/cactuscon-dcc" }; | |
get("funstuff", function(err, data){ | |
console.log(data); | |
}); | |
function get(collectionname, callback){ | |
mongo.connect(settings.mongo, function(err, db){ | |
var collection = db.collection(collectionname); | |
var cursor = collection.find(); | |
collection.find().toArray(function(err, results){ | |
if(err) {console.log("find failed:", err); callback(err); return;} | |
callback(err, results); | |
db.close(); | |
}); | |
}); | |
} |
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
//This connects to a "cloud" mongo instance, yes, that's the password | |
var mongo = require('mongodb').MongoClient; | |
var settings = { mongo: "mongodb://cactuscon:Wish2PacWasAlive23423524545234@ds029630.mongolab.com:29630/cactuscon-dcc" }; | |
var ourData = { | |
name:"Your Name Here", | |
message:"Your Message" | |
}; | |
save("funstuff", ourData, function(err, object){ | |
if(err) {console.log("saved failed:", err); return;} | |
console.log("saved: ", object); | |
}); | |
function save(collectionName, object, callback) { | |
mongo.connect(settings.mongo, function(err, db){ | |
if(err) {console.log("connect failed:", err); callback(err); return; | |
} else { | |
var collection = db.collection(collectionName); | |
collection.insert(object, {}, function() { | |
callback(null, object); | |
}); | |
db.close(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment