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