userver: userver/storages/mongo/pool.hpp Source File
Loading...
Searching...
No Matches
pool.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <memory>
7#include <string>
8#include <vector>
9
20
21USERVER_NAMESPACE_BEGIN
22
23namespace storages::mongo {
24
25namespace impl {
26class PoolImpl;
27} // namespace impl
28
40class Pool {
41public:
42 Pool(Pool&&) noexcept;
43 Pool& operator=(Pool&&) noexcept;
44 ~Pool();
45
48
50 Collection GetCollection(std::string name) const;
51
55
57 std::vector<std::string> ListCollectionNames() const;
58
60 void Ping();
61
67
79 template <typename... Options>
80 Cursor Aggregate(formats::bson::Value pipeline, Options&&... options);
81
84 Cursor Execute(const operations::Aggregate&);
86
88 // For internal use only
89 Pool(
90 std::string id,
91 const std::string& uri,
92 const PoolConfig& pool_config,
93 clients::dns::Resolver* dns_resolver,
94 dynamic_config::Source config_source
95 );
96
97 // Writes pool statistics
98 friend void DumpMetric(utils::statistics::Writer& writer, const Pool& pool);
99
100 friend std::shared_ptr<impl::PoolImpl> GetPoolImpl(const Pool& pool) { return pool.impl_; }
101
102 // Sets new dynamic pool settings
103 void SetPoolSettings(const PoolSettings& pool_settings);
104
105 void SetConnectionString(const std::string& connection_string);
107
108private:
109 std::shared_ptr<impl::PoolImpl> impl_;
110};
111
112using PoolPtr = std::shared_ptr<Pool>;
113
114template <typename... Options>
116 operations::Aggregate aggregate(std::move(pipeline));
117 (aggregate.SetOption(std::forward<Options>(options)), ...);
118 return Execute(aggregate);
119}
120
121} // namespace storages::mongo
122
123USERVER_NAMESPACE_END