-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
81 lines (66 loc) · 2.21 KB
/
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
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
69
70
71
72
73
74
75
76
77
78
79
80
/**
* Created by mikedanylov on 10/1/16.
*/
var config = require('./config');
var uri = process.env.MONGOLAB_URI || config.mongoUri;
var mongoose = require('mongoose');
mongoose.connect(uri);
var db = mongoose.connection;
db.on('error', function (err) {
console.log('Failed to connect to mongodb', err);
});
db.once('open', function (resp) {
console.log('Connected to mongodb, uri: ' + uri);
});
var eventSchema = mongoose.Schema({
viewUrl : String,
type : String,
origX : Number,
origY : Number,
scaledX : Number,
scaledY : Number,
selector : String,
timestamp : Date,
width : Number,
height : Number,
platform : String,
modifications: [String]
});
eventSchema.statics.findEvents = function (queryParams, remove, cb) {
return this.find({
type : queryParams.type,
platform : queryParams.platform,
viewUrl : queryParams.url,
$and : [
{ timestamp: { $gt: queryParams.startTime } },
{ timestamp: { $lt: queryParams.endTime } }
]
}, remove).exec(cb);
};
eventSchema.statics.findEventsWithModifications = function (queryParams, remove, cb) {
this.find({
type : queryParams.type,
platform : queryParams.platform,
viewUrl : queryParams.url,
$and : [
{ timestamp: { $gt: queryParams.startTime } },
{ timestamp: { $lt: queryParams.endTime } }
],
modifications: {$all: queryParams.modifications}
}, remove).exec(cb);
};
eventSchema.statics.findEventsWithModificationsExclusive = function (queryParams, remove, cb) {
this.find({
type : queryParams.type,
platform : queryParams.platform,
viewUrl : queryParams.url,
$and : [
{ timestamp: { $gt: queryParams.startTime } },
{ timestamp: { $lt: queryParams.endTime } },
{modifications: {$all: queryParams.modifications}},
{modifications: {$size: queryParams.modifications.length}}
]
}, remove).exec(cb);
};
var Event = mongoose.model('Event', eventSchema);
exports.Event = Event;