-
Notifications
You must be signed in to change notification settings - Fork 17
/
modify_db.js
33 lines (27 loc) · 863 Bytes
/
modify_db.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
var mongo = require('mongodb');
var NAME_COLLECTION = "your_collection";
var DB_URL = "mongodb://127.0.0.1:27017/your_db";
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect(DB_URL, function(err, db) {
if(err) throw err;
var collection = db.collection(NAME_COLLECTION);
// Locate all the entries using find
collection.find().toArray(function(err, docs) {
for (i=0;i<docs.length;i++) {
console.log("Modify _id:"+docs[i]._id);
modifyDate(collection, docs[i]);
}
db.close();
console.log("End modification USER_CRASH_DATE");
});
})
function modifyDate(collection, doc){
doc.USER_CRASH_DATE = new Date(doc.USER_CRASH_DATE);
collection.update({_id:doc._id }, {
$set: { 'USER_CRASH_DATE': doc.USER_CRASH_DATE },
}, function(err) {
if (!err) {
console.log("Error:"+err);
}
});
}