-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsthack_tasks_mongo.js
More file actions
35 lines (31 loc) · 917 Bytes
/
sthack_tasks_mongo.js
File metadata and controls
35 lines (31 loc) · 917 Bytes
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
var config = require('./config.json');
var mongodb = require('mongodb');
var Db = mongodb.Db;
var Server = mongodb.Server;
process.on('message',function(data) {
var db = new Db(config.mongo.db, new Server(config.mongo.ip, config.mongo.port, {auto_reconnect: true}),{safe: true});
db.open(function(err, db) {
if(!err) {
db.authenticate(config.mongo.login, config.mongo.password, function(err, result) {
if(!err) {
db.collection('tasks', function(err, coll) {
if(!err) {
coll.find().toArray(function(err, cursor) {
process.send(cursor);
db.logout(function(err, result) {
db.close();
});
});
}
else
console.dir(err);
});
}
else
console.dir(err);
});
}
else
console.dir(err);
});
});