forked from dannybrian/nfjs-fullstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongo-update.js
37 lines (35 loc) · 1005 Bytes
/
mongo-update.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var mongodb = require('mongodb').MongoClient;
var assert = require('assert');
var async = require('async');
var updateUser = function (db, username, callback) {
var users = db.collection('users');
users.update({
a: 2
}, // match these docs
{
$set: {
user: "Daniel"
}
}, // set this
{
upsert: true
}, // insert if no matches
function (err, result) {
console.log("updated record for " + username);
process.exit();
}
);
}
async.parallel({
db: function (callback) {
mongodb.connect('mongodb://localhost:27017/quiz', function (err, db) {
assert.equal(null, err);
console.log('Connected correctly to mongodb server');
callback(null, db);
});
},
},
function (err, results) {
console.log('connection');
updateUser(results.db, 'danny');
});