-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssidtracking.js
68 lines (60 loc) · 1.7 KB
/
ssidtracking.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var Db = require('mongodb').Db;
var Connection = require('mongodb').Connection;
var Server = require('mongodb').Server;
var BSON = require('mongodb').BSON;
var ObjectID = require('mongodb').ObjectID;
console.log("Setting up DB");
SSIDProvider = function(host, port) {
console.log("Mongo: Setting up DB SSID");
this.db = new Db('logistics-tracking', new Server(host, port, {
auto_reconnect : true
}, {}));
this.db.open(function() {
});
};
SSIDProvider.prototype.getCollection = function(callback) {
console.log("Mongo: in getCollection");
this.db.collection('ssid', function(error, article_collection) {
if (error)
callback(error);
else
callback(null, article_collection);
});
};
SSIDProvider.prototype.count = function(callback) {
console.log("getting count");
this.getCollection(function(error, track_collection) {
if (error) {
callback(error, 0)
} else {
track_collection.count(function(e, count) {
return callback(e, count)
});
}
});
};
SSIDProvider.prototype.save = function(tracks, callback) {
console.log("Mongo: in save");
this.getCollection(function(error, track_collection) {
if (error)
callback(error)
else {
if (typeof (tracks.length) == "undefined")
tracks = [ tracks ];
for ( var i = 0; i < tracks.length; i++) {
track = tracks[i];
track.created_at = new Date();
// if( article.comments === undefined ) article.comments = [];
// for(var j =0;j< article.comments.length; j++) {
// article.comments[j].created_at = new Date();
// }
}
console.log("Going to insert");
track_collection.insert(tracks, function() {
console.log("inserted")
callback(null, tracks);
});
}
});
};
exports.SSIDProvider = SSIDProvider;