Skip to content

Instantly share code, notes, and snippets.

@savokiss
Created February 17, 2017 03:06
Show Gist options
  • Save savokiss/4d631ff3179d945d20651a97f252aebf to your computer and use it in GitHub Desktop.
Save savokiss/4d631ff3179d945d20651a97f252aebf to your computer and use it in GitHub Desktop.
mongodb insert.js
var mongo = require('mongodb').MongoClient;
var dbName = process.argv[2];
var url = 'mongodb://localhost:27017/'+dbName;
mongo.connect(url, function(err, db){
if(err) throw err;
var col = db.collection('users');
col.update({
username: 'tinatime'
},{
$set: {
age: 40
}
},function(err,data){
if(err) throw err;
db.close();
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment