blob: 3e7ae3df6935a393f059b8ec6f54fa7eff4c7b5d (
plain) (
blame)
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
|
#include "mongoStub.hpp"
mongoStub::mongoStub() {
if (this->client) {
this->db = client["fosscord"];
if (this->db) {
this->col = db["events"];
} else {
std::cout << "db not found";
exit(-1);
}
} else {
std::cout << "Client couldn't be initialized";
exit(-1);
}
}
//Too slow for my liking
std::vector<mongoStub::mongoMessage> mongoStub::getNewMessages(mongocxx::change_stream* colCs) {
std::vector<mongoStub::mongoMessage> retVec;
for (auto&& event : *colCs) {
mongoStub::mongoMessage returnValue;
/*if(event["fullDocument"]["data"]){
returnValue.data.push_back(event["fullDocument"]["data"].get_utf8().value.to_string());
}*/
std::cout << bsoncxx::to_json(event) << std::endl;
//Oly listen to insert events (to avoid "precondition failed: data" exception)
if(event["operationType"].get_utf8().value.to_string()!="insert"){
continue;
}
returnValue.eventName = event["fullDocument"]["event"].get_utf8().value.to_string();
retVec.push_back(returnValue);
}
return retVec;
}
|