Repository navigation
Expand file tree
/
Copy pathclient.hpp
More file actions
376 lines (336 loc) · 12.7 KB
/
Copy pathclient.hpp
File metadata and controls
376 lines (336 loc) · 12.7 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
// Copyright 2014-present MongoDB Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <memory>
#include <mongocxx/client_session.hpp>
#include <mongocxx/database.hpp>
#include <mongocxx/options/client.hpp>
#include <mongocxx/options/client_session.hpp>
#include <mongocxx/read_concern.hpp>
#include <mongocxx/read_preference.hpp>
#include <mongocxx/stdx.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/write_concern.hpp>
#include <mongocxx/config/prelude.hpp>
///
/// Top level namespace for the MongoDB C++ driver.
///
namespace mongocxx {
MONGOCXX_INLINE_NAMESPACE_BEGIN
class client_session;
///
/// Class representing a client connection to MongoDB.
///
/// Acts as a logical gateway for working with databases contained within a MongoDB server.
///
/// Databases that are created via this client inherit the @c read_concern, @c read_preference, and
/// @c write_concern settings of this client when they are created. The lifetimes of objects created
/// via a client object (databases, collections, cursors, etc...) @b must be a subset of the
/// lifetime of the client that created them.
///
/// Example:
/// @code
/// mongocxx::client mongo_client{mongocxx::uri{}};
/// mongocxx::client mongo_client{mongocxx::uri{"mongodb://localhost:27017"}};
/// @endcode
///
/// Note that client is not thread-safe. See
/// https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/thread-safety/ for more details.
class MONGOCXX_API client {
public:
///
/// Default constructs a new client. The client is not connected and is equivalent to the
/// state of a moved-from client. The only valid actions to take with a default constructed
/// 'client' are to assign to it, or destroy it.
///
client() noexcept;
///
/// Creates a new client connection to MongoDB.
///
/// @param mongodb_uri
/// A MongoDB URI representing the connection parameters
/// @param options
/// Additional options that cannot be specified via the mongodb_uri
///
/// @throws mongocxx::exception if invalid options are provided
/// (whether from the URI or provided client options).
///
client(const class uri& mongodb_uri, const options::client& options = options::client());
///
/// Move constructs a client.
///
client(client&&) noexcept;
///
/// Move assigns a client.
///
client& operator=(client&&) noexcept;
///
/// Destroys a client.
///
~client();
///
/// Returns true if the client is valid, meaning it was not default constructed
/// or moved from.
///
explicit operator bool() const noexcept;
///
/// Sets the read concern for this client.
///
/// Modifications at this level do not affect existing database instances that have been
/// created by this client but do affect new ones as databases inherit the @c read_concern
/// settings of their parent upon instantiation.
///
/// @deprecated
/// This method is deprecated. Read concerns should be set either in the URI or directly on
/// database or collection objects.
///
/// @param rc
/// The new @c read_concern
///
/// @see https://docs.mongodb.com/master/reference/read-concern/
///
MONGOCXX_DEPRECATED void read_concern(class read_concern rc);
void read_concern_deprecated(class read_concern rc);
///
/// Returns the current read concern for this client.
///
/// @return The current @c read_concern
///
class read_concern read_concern() const;
///
/// Sets the read preference for this client.
///
/// Modifications at this level do not affect existing database instances that have been
/// created by this client but do affect new ones as databases inherit the @c read_preference
/// settings of their parent upon instantiation.
///
/// @deprecated
/// This method is deprecated. Read preferences should be set either in the URI or directly on
/// database or collection objects.
///
/// @param rp
/// The new @c read_preference
///
/// @see https://docs.mongodb.com/master/core/read-preference/
///
MONGOCXX_DEPRECATED void read_preference(class read_preference rp);
void read_preference_deprecated(class read_preference rp);
///
/// Returns the current read preference for this client.
///
/// @return The current @c read_preference
///
/// @see https://docs.mongodb.com/master/core/read-preference/
///
class read_preference read_preference() const;
///
/// Returns the current uri for this client.
///
/// @return The @c uri that this client was created with.
///
class uri uri() const;
///
/// Sets the write concern for this client.
///
/// @note Modifications at this level do not affect existing databases or collection instances
/// that have come from this client but do affect new ones as databases will receive a copy of
/// this client's @c write_concern upon instantiation.
///
/// @deprecated
/// This method is deprecated. Write concerns should be set either in the URI or directly on
/// database or collection objects.
///
/// @param wc
/// The new write concern
///
MONGOCXX_DEPRECATED void write_concern(class write_concern wc);
void write_concern_deprecated(class write_concern wc);
///
/// Returns the current write concern for this client.
///
/// @return the current @c write_concern
class write_concern write_concern() const;
///
/// Obtains a database that represents a logical grouping of collections on a MongoDB server.
///
/// @note A database cannot be obtained from a temporary client object.
///
/// @param name
/// The name of the database to get
///
/// @return The database
///
class database database(bsoncxx::string::view_or_value name) const&;
class database database(bsoncxx::string::view_or_value name) const&& = delete;
///
/// Allows the syntax @c client["db_name"] as a convenient shorthand for the client::database()
/// method by implementing the array subscript operator.
///
/// @note A database cannot be obtained from a temporary client object.
///
/// @param name
/// The name of the database.
///
/// @return Client side representation of a server side database
///
MONGOCXX_INLINE class database operator[](bsoncxx::string::view_or_value name) const&;
MONGOCXX_INLINE class database operator[](bsoncxx::string::view_or_value name) const&& = delete;
///
/// @{
///
/// Enumerates the databases in the client.
///
/// @return A mongocxx::cursor containing a BSON document for each
/// database. Each document contains a name field with the database
/// name, a sizeOnDisk field with the total size of the database file on
/// disk in bytes, and an empty field specifying whether the database
/// has any data.
///
/// @throws mongocxx::operation_exception if the underlying 'listDatabases' command fails.
///
/// @see https://docs.mongodb.com/master/reference/command/listDatabases
///
cursor list_databases() const;
///
/// Enumerates the databases in the client.
///
/// @param session
/// The mongocxx::client_session with which to perform the aggregation.
///
/// @return A mongocxx::cursor containing a BSON document for each
/// database. Each document contains a name field with the database
/// name, a sizeOnDisk field with the total size of the database file on
/// disk in bytes, and an empty field specifying whether the database
/// has any data.
///
/// @throws mongocxx::operation_exception if the underlying 'listDatabases' command fails.
///
/// @see https://docs.mongodb.com/master/reference/command/listDatabases
///
cursor list_databases(const client_session& session) const;
///
/// Enumerates the databases in the client.
///
/// @param filter
/// The filter that documents must match in order to be listed.
///
/// @return A mongocxx::cursor containing a BSON document for each
/// database. Each document contains a name field with the database
/// name, a sizeOnDisk field with the total size of the database file on
/// disk in bytes, and an empty field specifying whether the database
/// has any data.
///
/// @throws mongocxx::operation_exception if the underlying 'listDatabases' command fails.
///
/// @see https://docs.mongodb.com/master/reference/command/listDatabases
///
cursor list_databases(const bsoncxx::document::view_or_value filter) const;
///
/// @}
///
///
/// Create a client session for a sequence of operations.
///
/// @return A client_session object. See `mongocxx::client_session` for more information.
///
/// @throws mongocxx::operation_exception if the driver is not built with crypto support, if
/// options is misconfigured, or if the session is configured with options that the server does
/// not support.
///
client_session start_session(const options::client_session& options = {});
///
/// @{
///
/// Gets a change stream on this client with an empty pipeline.
/// Change streams are only supported with a "majority" read concern or no read concern.
///
/// @param options
/// The options to use when creating the change stream.
///
/// @return
/// A change stream on this client.
///
/// @see https://docs.mongodb.com/manual/changeStreams/
///
change_stream watch(const options::change_stream& options = {});
///
/// @param session
/// The mongocxx::client_session with which to perform the watch operation.
/// @param options
/// The options to use when creating the change stream.
///
/// @return
/// A change stream on this client.
///
/// @see https://docs.mongodb.com/manual/changeStreams/
///
change_stream watch(const client_session& session, const options::change_stream& options = {});
///
/// Gets a change stream on this client.
/// Change streams are only supported with a "majority" read concern or no read concern.
///
/// @param pipe
/// The aggregation pipeline to be used on the change notifications.
/// Only a subset of pipeline operations are supported for change streams. For more
/// information see the change streams documentation.
/// @param options
/// The options to use when creating the change stream.
///
/// @return
/// A change stream on this client.
///
/// @see https://docs.mongodb.com/manual/changeStreams/
///
change_stream watch(const pipeline& pipe, const options::change_stream& options = {});
///
/// Gets a change stream on this client.
///
/// @param session
/// The mongocxx::client_session with which to perform the watch operation.
/// @param pipe
/// The aggregation pipeline to be used on the change notifications.
/// @param options
/// The options to use when creating the change stream.
///
/// @return
/// A change stream on this client.
///
/// @see https://docs.mongodb.com/manual/changeStreams/
///
change_stream watch(const client_session& session,
const pipeline& pipe,
const options::change_stream& options = {});
///
/// @}
///
private:
friend class collection;
friend class database;
friend class pool;
friend class client_session;
MONGOCXX_PRIVATE explicit client(void* implementation);
MONGOCXX_PRIVATE change_stream _watch(const client_session* session,
const pipeline& pipe,
const options::change_stream& options);
class MONGOCXX_PRIVATE impl;
MONGOCXX_PRIVATE impl& _get_impl();
MONGOCXX_PRIVATE const impl& _get_impl() const;
std::unique_ptr<impl> _impl;
};
MONGOCXX_INLINE database client::operator[](bsoncxx::string::view_or_value name) const& {
return database(name);
}
MONGOCXX_INLINE_NAMESPACE_END
} // namespace mongocxx
#include <mongocxx/config/postlude.hpp>