userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
operations.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/storages/mongo/operations.hpp
4
/// @brief Collection operation models
5
6
#
include
<
userver
/
formats
/
bson
/
document
.
hpp
>
7
#
include
<
userver
/
formats
/
bson
/
value
.
hpp
>
8
#
include
<
userver
/
storages
/
mongo
/
options
.
hpp
>
9
#
include
<
userver
/
utils
/
fast_pimpl
.
hpp
>
10
11
USERVER_NAMESPACE_BEGIN
12
13
namespace
storages::mongo::impl {
14
class
Database;
15
}
// namespace storages::mongo::impl
16
17
namespace
storages::mongo::impl::cdriver {
18
class
CDriverCollectionImpl;
19
class
CDriverTransactionCollectionImpl;
20
}
// namespace storages::mongo::impl::cdriver
21
22
/// Collection operations
23
namespace
storages::mongo::
operations
{
24
25
/// Counts documents matching the filter
26
class
Count
{
27
public
:
28
explicit
Count(formats::
bson
::
Document
filter);
29
~Count();
30
31
Count(
const
Count
&);
32
Count(
Count
&&)
noexcept
;
33
Count
& operator=(
const
Count
&);
34
Count
& operator=(
Count
&&)
noexcept
;
35
36
void
SetOption(
const
options
::
ReadPreference
&);
37
void
SetOption(
options
::
ReadPreference
::
Mode
);
38
void
SetOption(
options
::
ReadConcern
);
39
void
SetOption(
options
::
Skip
);
40
void
SetOption(
options
::
Limit
);
41
void
SetOption(
const
options
::
MaxServerTime
&);
42
void
SetOption(
const
options
::
Hint
&);
43
44
private
:
45
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
46
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
47
48
class
Impl;
49
static
constexpr
size_t kSize = 96;
50
static
constexpr
size_t kAlignment = 8;
51
// MAC_COMPAT: std::string size differs
52
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
53
};
54
55
/// Returns approximate number of documents in a collection
56
class
CountApprox
{
57
public
:
58
CountApprox();
59
~CountApprox();
60
61
CountApprox(
const
CountApprox
&);
62
CountApprox(
CountApprox
&&)
noexcept
;
63
CountApprox
& operator=(
const
CountApprox
&);
64
CountApprox
& operator=(
CountApprox
&&)
noexcept
;
65
66
void
SetOption(
const
options
::
ReadPreference
&);
67
void
SetOption(
options
::
ReadPreference
::
Mode
);
68
void
SetOption(
options
::
ReadConcern
);
69
void
SetOption(
options
::
Skip
);
70
void
SetOption(
options
::
Limit
);
71
void
SetOption(
const
options
::
MaxServerTime
&);
72
73
private
:
74
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
75
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
76
77
class
Impl;
78
static
constexpr
size_t kSize = 72;
79
static
constexpr
size_t kAlignment = 8;
80
// MAC_COMPAT: std::string size differs
81
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
82
};
83
84
/// Retrieves documents matching the filter
85
class
Find
{
86
public
:
87
explicit
Find(formats::
bson
::
Document
filter);
88
~Find();
89
90
Find(
const
Find
&);
91
Find(
Find
&&)
noexcept
;
92
Find
& operator=(
const
Find
&);
93
Find
& operator=(
Find
&&)
noexcept
;
94
95
void
SetOption(
const
options
::
ReadPreference
&);
96
void
SetOption(
options
::
ReadPreference
::
Mode
);
97
void
SetOption(
options
::
ReadConcern
);
98
void
SetOption(
options
::
Skip
);
99
void
SetOption(
options
::
Limit
);
100
void
SetOption(
options
::
BatchSize
);
101
void
SetOption(
options
::
Projection
);
102
void
SetOption(
const
options
::
Sort
&);
103
void
SetOption(
const
options
::
Hint
&);
104
void
SetOption(
options
::
AllowPartialResults
);
105
void
SetOption(
options
::
Tailable
);
106
void
SetOption(
const
options
::
Comment
&);
107
void
SetOption(
const
options
::
MaxServerTime
&);
108
109
private
:
110
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
111
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
112
113
class
Impl;
114
static
constexpr
size_t kSize = 96;
115
static
constexpr
size_t kAlignment = 8;
116
// MAC_COMPAT: std::string size differs
117
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
118
};
119
120
/// Inserts a single document
121
class
InsertOne
{
122
public
:
123
explicit
InsertOne(formats::
bson
::
Document
document);
124
~InsertOne();
125
126
InsertOne(
const
InsertOne
&);
127
InsertOne(
InsertOne
&&)
noexcept
;
128
InsertOne
& operator=(
const
InsertOne
&);
129
InsertOne
& operator=(
InsertOne
&&)
noexcept
;
130
131
void
SetOption(
options
::
WriteConcern
::
Level
);
132
void
SetOption(
const
options
::
WriteConcern
&);
133
void
SetOption(
options
::
SuppressServerExceptions
);
134
void
SetOption(
const
options
::
MaxServerTime
&);
135
136
private
:
137
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
138
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
139
140
class
Impl;
141
static
constexpr
size_t kSize = 88;
142
static
constexpr
size_t kAlignment = 8;
143
// MAC_COMPAT: std::string size differs
144
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
145
};
146
147
/// Inserts multiple documents
148
class
InsertMany
{
149
public
:
150
InsertMany();
151
explicit
InsertMany(std::vector<formats::
bson
::
Document
> documents);
152
~InsertMany();
153
154
InsertMany(
const
InsertMany
&);
155
InsertMany(
InsertMany
&&)
noexcept
;
156
InsertMany
& operator=(
const
InsertMany
&);
157
InsertMany
& operator=(
InsertMany
&&)
noexcept
;
158
159
void
Append(formats::
bson
::
Document
document);
160
161
void
SetOption(
options
::
Unordered
);
162
void
SetOption(
options
::
WriteConcern
::
Level
);
163
void
SetOption(
const
options
::
WriteConcern
&);
164
void
SetOption(
options
::
SuppressServerExceptions
);
165
void
SetOption(
const
options
::
MaxServerTime
&);
166
167
private
:
168
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
169
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
170
171
class
Impl;
172
static
constexpr
size_t kSize = 96;
173
static
constexpr
size_t kAlignment = 8;
174
// MAC_COMPAT: std::string size differs
175
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
176
};
177
178
/// Replaces a single document
179
class
ReplaceOne
{
180
public
:
181
ReplaceOne(formats::
bson
::
Document
selector, formats::
bson
::
Document
replacement);
182
~ReplaceOne();
183
184
ReplaceOne(
const
ReplaceOne
&);
185
ReplaceOne(
ReplaceOne
&&)
noexcept
;
186
ReplaceOne
& operator=(
const
ReplaceOne
&);
187
ReplaceOne
& operator=(
ReplaceOne
&&)
noexcept
;
188
189
void
SetOption(
options
::
Upsert
);
190
void
SetOption(
options
::
WriteConcern
::
Level
);
191
void
SetOption(
const
options
::
WriteConcern
&);
192
void
SetOption(
options
::
SuppressServerExceptions
);
193
void
SetOption(
const
options
::
MaxServerTime
&);
194
195
private
:
196
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
197
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
198
199
class
Impl;
200
static
constexpr
size_t kSize = 104;
201
static
constexpr
size_t kAlignment = 8;
202
// MAC_COMPAT: std::string size differs
203
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
204
};
205
206
/// Updates documents
207
class
Update
{
208
public
:
209
enum
class
Mode { kSingle, kMulti };
210
211
Update(Mode mode, formats::
bson
::
Document
selector, formats::
bson
::
Document
update);
212
213
/// @brief Creates an update operation with an aggregation pipeline
214
/// @note `update` must be either an update document or an aggregation pipeline array
215
/// @note Available starting in MongoDB 4.2
216
Update
(Mode mode, formats::
bson
::
Document
selector, formats::
bson
::
Value
update);
217
218
~Update();
219
220
Update(
const
Update
&);
221
Update(
Update
&&)
noexcept
;
222
Update
& operator=(
const
Update
&);
223
Update
& operator=(
Update
&&)
noexcept
;
224
225
void
SetOption(
options
::
Upsert
);
226
void
SetOption(
options
::
RetryDuplicateKey
);
227
void
SetOption(
options
::
WriteConcern
::
Level
);
228
void
SetOption(
const
options
::
WriteConcern
&);
229
void
SetOption(
options
::
SuppressServerExceptions
);
230
void
SetOption(
const
options
::
ArrayFilters
&);
231
void
SetOption(
const
options
::
MaxServerTime
&);
232
233
/// @note Available starting in MongoDB 4.2.1
234
void
SetOption
(
const
options
::
Hint
&);
235
236
private
:
237
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
238
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
239
240
class
Impl;
241
static
constexpr
size_t kSize = 104;
242
static
constexpr
size_t kAlignment = 8;
243
// MAC_COMPAT: std::string size differs
244
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
245
};
246
247
/// Deletes documents
248
class
Delete
{
249
public
:
250
enum
class
Mode { kSingle, kMulti };
251
252
Delete(Mode mode, formats::
bson
::
Document
selector);
253
~Delete();
254
255
Delete(
const
Delete
&);
256
Delete(
Delete
&&)
noexcept
;
257
Delete
& operator=(
const
Delete
&);
258
Delete
& operator=(
Delete
&&)
noexcept
;
259
260
void
SetOption(
options
::
WriteConcern
::
Level
);
261
void
SetOption(
const
options
::
WriteConcern
&);
262
void
SetOption(
options
::
SuppressServerExceptions
);
263
264
/// @note Available starting in MongoDB 4.4
265
void
SetOption
(
const
options
::
Hint
&);
266
267
void
SetOption(
const
options
::
MaxServerTime
&);
268
269
private
:
270
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
271
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
272
273
class
Impl;
274
static
constexpr
size_t kSize = 88;
275
static
constexpr
size_t kAlignment = 8;
276
// MAC_COMPAT: std::string size differs
277
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
278
};
279
280
/// Atomically updates a document and returns either previous or new version
281
class
FindAndModify
{
282
public
:
283
FindAndModify(formats::
bson
::
Document
query,
const
formats::
bson
::
Document
& update);
284
~FindAndModify();
285
286
FindAndModify(
const
FindAndModify
&) =
delete
;
287
FindAndModify(
FindAndModify
&&)
noexcept
;
288
FindAndModify
& operator=(
const
FindAndModify
&) =
delete
;
289
FindAndModify
& operator=(
FindAndModify
&&)
noexcept
;
290
291
void
SetOption(
options
::
ReturnNew
);
292
void
SetOption(
options
::
Upsert
);
293
void
SetOption(
options
::
RetryDuplicateKey
);
294
void
SetOption(
const
options
::
Sort
&);
295
void
SetOption(
options
::
Projection
);
296
void
SetOption(
options
::
WriteConcern
::
Level
);
297
void
SetOption(
const
options
::
WriteConcern
&);
298
void
SetOption(
const
options
::
MaxServerTime
&);
299
void
SetOption(
const
options
::
ArrayFilters
&);
300
301
private
:
302
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
303
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
304
305
class
Impl;
306
FindAndModify(Impl&&);
307
static
constexpr
size_t kSize = 80;
308
static
constexpr
size_t kAlignment = 8;
309
// MAC_COMPAT: std::string size differs
310
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
311
};
312
313
/// Atomically removes a document and returns it
314
class
FindAndRemove
{
315
public
:
316
explicit
FindAndRemove(formats::
bson
::
Document
query);
317
~FindAndRemove();
318
319
FindAndRemove(
const
FindAndRemove
&) =
delete
;
320
FindAndRemove(
FindAndRemove
&&)
noexcept
;
321
FindAndRemove
& operator=(
const
FindAndRemove
&) =
delete
;
322
FindAndRemove
& operator=(
FindAndRemove
&&)
noexcept
;
323
324
void
SetOption(
const
options
::
Sort
&);
325
void
SetOption(
options
::
Projection
);
326
void
SetOption(
options
::
WriteConcern
::
Level
);
327
void
SetOption(
const
options
::
WriteConcern
&);
328
void
SetOption(
const
options
::
MaxServerTime
&);
329
330
private
:
331
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
332
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
333
334
class
Impl;
335
FindAndRemove(Impl&&);
336
static
constexpr
size_t kSize = 72;
337
static
constexpr
size_t kAlignment = 8;
338
// MAC_COMPAT: std::string size differs
339
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
340
};
341
342
/// Runs an aggregation pipeline
343
class
Aggregate
{
344
public
:
345
explicit
Aggregate(formats::
bson
::
Value
pipeline);
346
~Aggregate();
347
348
Aggregate(
const
Aggregate
&);
349
Aggregate(
Aggregate
&&)
noexcept
;
350
Aggregate
& operator=(
const
Aggregate
&);
351
Aggregate
& operator=(
Aggregate
&&)
noexcept
;
352
353
void
SetOption(
const
options
::
ReadPreference
&);
354
void
SetOption(
options
::
ReadPreference
::
Mode
);
355
void
SetOption(
options
::
ReadConcern
);
356
void
SetOption(
const
options
::
WriteConcern
&);
357
void
SetOption(
options
::
WriteConcern
::
Level
);
358
void
SetOption(
const
options
::
Hint
&);
359
void
SetOption(
const
options
::
Comment
&);
360
void
SetOption(
const
options
::
MaxServerTime
&);
361
362
private
:
363
friend
class
storages::mongo::impl::Database;
364
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
365
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
366
367
class
Impl;
368
static
constexpr
size_t kSize = 120;
369
static
constexpr
size_t kAlignment = 8;
370
// MAC_COMPAT: std::string size differs
371
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
372
};
373
374
/// Retrieves distinct values for a specified field
375
class
Distinct
final
{
376
public
:
377
explicit
Distinct(std::string field);
378
Distinct(std::string field, formats::
bson
::
Document
filter);
379
~Distinct();
380
381
Distinct(
const
Distinct&);
382
Distinct(Distinct&&)
noexcept
;
383
Distinct& operator=(
const
Distinct&);
384
Distinct& operator=(Distinct&&)
noexcept
;
385
386
void
SetOption(
const
options
::
ReadPreference
&);
387
void
SetOption(
options
::
ReadPreference
::
Mode
);
388
void
SetOption(
options
::
ReadConcern
);
389
void
SetOption(
const
options
::Collation&);
390
void
SetOption(
const
options
::
Comment
&);
391
void
SetOption(
const
options
::
MaxServerTime
&);
392
393
private
:
394
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
395
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
396
397
class
Impl;
398
static
constexpr
size_t kSize = 104;
399
static
constexpr
size_t kAlignment = 8;
400
// MAC_COMPAT: std::string size differs
401
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
402
};
403
404
class
Drop
{
405
public
:
406
Drop();
407
~Drop();
408
409
Drop(
const
Drop
&);
410
Drop(
Drop
&&)
noexcept
;
411
Drop
& operator=(
const
Drop
&);
412
Drop
& operator=(
Drop
&&)
noexcept
;
413
414
void
SetOption(
const
options
::
WriteConcern
&);
415
void
SetOption(
options
::
WriteConcern
::
Level
);
416
417
private
:
418
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
419
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
420
421
class
Impl;
422
static
constexpr
size_t kSize = 56;
423
static
constexpr
size_t kAlignment = 8;
424
// MAC_COMPAT: std::string size differs
425
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
426
};
427
428
}
// namespace storages::mongo::operations
429
430
USERVER_NAMESPACE_END
userver
storages
mongo
operations.hpp
Generated on
for userver by
Doxygen
1.17.0