-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdump_logs.js
More file actions
executable file
·56 lines (50 loc) · 1.63 KB
/
dump_logs.js
File metadata and controls
executable file
·56 lines (50 loc) · 1.63 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
/**
* dump_logs.js
* Dumps the log database in log file format.
*/
var mongodb = require('mongodb'),
server = new mongodb.Server('127.0.0.1', '27017', {}),
connection = new mongodb.Db('bioasq-at', server, { safe: false }),
querystring = require('querystring');
connection.open(function (err, conn) {
if (err) {
process.stdout.write('Could not open connection.');
process.exit(-1);
}
conn.collection('log', function (err, log) {
if (err) {
process.stdout.write('Could not open `logs` collection.');
process.exit(-1);
}
/*
* TODO: Modify here to change the query
*/
var cursor = log.find(
{ path: 'login' }, // db query: set key and value of the fields to match
{ time: false, _id: false } // set fields to not return to false
);
cursor.count(function (err, count) {
console.log(count + ' log entries found.');
cursor.each(function (err, doc) {
if (err) {
process.stdout.write('Could not retrieve document.');
process.exit(-1);
}
if (doc) {
printDoc(doc);
} else {
// the last entry will be `null`
process.exit(0);
}
});
});
});
});
var printDoc = function (doc) {
var valueStrings = [];
Object.keys(doc).forEach(function (key) {
valueStrings.push(key + '=' + JSON.stringify(doc[key]));
});
console.log(valueStrings.join(' '));
};