userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
pool.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/storages/mongo/pool.hpp
4
/// @brief @copybrief storages::mongo::Pool
5
6
#
include
<
memory
>
7
#
include
<
string
>
8
#
include
<
vector
>
9
10
#
include
<
userver
/
clients
/
dns
/
resolver_fwd
.
hpp
>
11
#
include
<
userver
/
dynamic_config
/
fwd
.
hpp
>
12
#
include
<
userver
/
storages
/
mongo
/
collection
.
hpp
>
13
#
include
<
userver
/
storages
/
mongo
/
pool_config
.
hpp
>
14
#
include
<
userver
/
storages
/
mongo
/
transaction
.
hpp
>
15
#
include
<
userver
/
utils
/
statistics
/
fwd
.
hpp
>
16
#
include
<
userver
/
utils
/
zstring_view
.
hpp
>
17
18
USERVER_NAMESPACE_BEGIN
19
20
namespace
storages::mongo {
21
22
namespace
impl {
23
class
PoolImpl;
24
}
// namespace impl
25
26
/// @ingroup userver_clients
27
///
28
/// @brief MongoDB client pool.
29
///
30
/// Use constructor only for tests, in production the pool should be retrieved
31
/// from @ref userver_components "the components" via
32
/// components::Mongo::GetPool() or components::MultiMongo::GetPool().
33
///
34
/// ## Example usage:
35
///
36
/// @snippet storages/mongo/collection_mongotest.hpp Sample Mongo usage
37
class
Pool
{
38
public
:
39
Pool(
Pool
&&)
noexcept
;
40
Pool
& operator=(
Pool
&&)
noexcept
;
41
~Pool();
42
43
/// Checks whether a collection exists
44
bool
HasCollection
(
utils
::
zstring_view
name)
const
;
45
46
/// Returns a handle for the specified collection
47
Collection
GetCollection
(std::string name)
const
;
48
49
/// Drops the associated database if it exists. New modifications of
50
/// collections will attempt to re-create the database automatically.
51
void
DropDatabase
();
52
53
/// Get a list of all the collection names in the associated database
54
std::vector<std::string>
ListCollectionNames
()
const
;
55
56
/// @throws storages::mongo::MongoException if failed to connect to the mongo server.
57
void
Ping
();
58
59
/// @brief Begin a new transaction.
60
///
61
/// @return Transaction handle for executing operations within transaction context
62
/// @throws MongoException if transaction cannot be started
63
Transaction
BeginTransaction
()
const
;
64
65
/// @cond
66
// For internal use only
67
Pool(
68
std::string id,
69
const
std::string& uri,
70
const
PoolConfig& pool_config,
71
clients::
dns
::
Resolver
* dns_resolver,
72
dynamic_config::Source config_source
73
);
74
75
// Writes pool statistics
76
friend
void
DumpMetric(
utils
::
statistics
::Writer& writer,
const
Pool
& pool);
77
78
// Sets new dynamic pool settings
79
void
SetPoolSettings(
const
PoolSettings& pool_settings);
80
81
void
SetConnectionString(
const
std::string& connection_string);
82
/// @endcond
83
84
private
:
85
std::shared_ptr<impl::PoolImpl> impl_;
86
};
87
88
using
PoolPtr = std::shared_ptr<
Pool
>;
89
90
}
// namespace storages::mongo
91
92
USERVER_NAMESPACE_END
userver
storages
mongo
pool.hpp
Generated on
for userver by
Doxygen
1.17.0