-
Notifications
You must be signed in to change notification settings - Fork 2
/
fill-db-with-fake-data-mongo.js
68 lines (54 loc) · 995 Bytes
/
fill-db-with-fake-data-mongo.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
var heartbeatCycleValues = [
10,
25,
50,
100,
200,
200,
100,
50,
25,
10
];
var currentDb = db.getMongo().getDB('heartbeat-monitor');
var days = 1;
var now = moment();
var time = moment().subtract('days', days);
var seconds30 = moment.duration(30, 'seconds');
var valCounter = 0;
var docs = [];
while (true) {
time = time.add(seconds30);
// print(time);
docs.push({
ts: time.clone().toDate(),
val: 36.6,
__v: 0
});
if (time > now) {
break;
}
}
print('inserting');
currentDb.temperatures.insert(docs, { writeConcern: 0 });
time = moment().subtract('days', days);
var ms10 = moment.duration(100, 'ms');
docs = [];
while (true) {
time = time.add(ms10);
docs.push({
ts: time.clone().toDate(),
val: heartbeatCycleValues[valCounter],
__v: 0
});
if (valCounter >= heartbeatCycleValues.length - 1) {
valCounter = 0;
} else {
valCounter++;
}
if (time > now) {
break;
}
}
print('inserting');
currentDb.heartbeats.insert(docs, { writeConcern: 0 });