-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
72 lines (67 loc) · 2.25 KB
/
main.cpp
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
#include <iostream>
#include <bsoncxx/types.hpp>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#include <bsoncxx/third_party/mnmlstc/core/optional.hpp>
#include "MongoDbHeader.h"
#include "DbConnectionPoolClient.h"
//#include "DbConnectionPool.h"
#include "BaseHeader.h"
io_service io(1);
DbConnectionPool db("mongodb://localhost:27017", "alien", 1);
DbConnectionPoolClient client(io, db);
int main(int, char**) {
function<void(void)> foo;
/*
* foo = [&]() {
document_vector_ptr documents = make_shared<document_vector>();
for(int i = 0; i < 1000; ++i)
documents->push_back(document{} << "lalka" << "test" << finalize);
client.insertMany("test", move(documents), [&](bool err, InsertManyResult res) {
foo();
});
};
*/
document_ptr testInsert = make_shared<document_value>(document{} << "name" << "test" << finalize);
int i = 0;
auto begin = time(0);
auto d =
foo = [&]() {
client.findOne("test", make_shared<document_value>(document{} << "name" << "test" << finalize),
[&](bool err, FindOneResult res) {
if(i%1000 == 0)
{
auto diff = time(0) - begin;
cout << float(i)/diff << endl;
}
if(*res) {
++i;
auto doc = *res;
//cout << bsoncxx::to_json(doc->view()) << endl;
foo();
}
else {
cout << "no result!" << endl;
}
});
};
//foo();
/*
client.deleteMany("test",
make_shared<document_value>(document{} << "name" << "suka" << finalize),
[](bool err, int32_t count) {
if(!err) {
cout << "deleted!" << endl;
}
});
*/
foo();
foo();
foo();
boost::asio::io_service::work work(io);
begin = time(0);
io.run();
cout << "exit" << endl;
}