Skip to content

Instantly share code, notes, and snippets.

@guiomie
Created June 25, 2011 18:52
Show Gist options
  • Save guiomie/1046775 to your computer and use it in GitHub Desktop.
Save guiomie/1046775 to your computer and use it in GitHub Desktop.
Function parameters not passed
var writeToCollection = function(collectionName, jsonObject){
try{
//the db name is hardcoded,
var collection = new mongo.Collection(db, collectionName);
collection.insert(jsonObject, {safe:true}, function(err, objects) {
if(err != null){
sys.log("Could not write JSON in collection ->" + err);
}
if (err && err.message.indexOf('E11000 ') !== -1) {
// this _id was already inserted in the database
sys.log("Id is already in DB ->" + err);
}
if(err === null){
sys.log("JSON added to database");
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment