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
131
private
:
132
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
133
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
134
135
class
Impl;
136
static
constexpr
size_t kSize = 80;
137
static
constexpr
size_t kAlignment = 8;
138
// MAC_COMPAT: std::string size differs
139
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
140
};
141
142
/// Inserts multiple documents
143
class
InsertMany
{
144
public
:
145
InsertMany();
146
explicit
InsertMany(std::vector<formats::
bson
::
Document
> documents);
147
~InsertMany();
148
149
InsertMany(
const
InsertMany
&);
150
InsertMany(
InsertMany
&&)
noexcept
;
151
InsertMany
& operator=(
const
InsertMany
&);
152
InsertMany
& operator=(
InsertMany
&&)
noexcept
;
153
154
void
Append(formats::
bson
::
Document
document);
155
156
void
SetOption(
options
::
Unordered
);
157
void
SetOption(
options
::
WriteConcern
::
Level
);
158
void
SetOption(
const
options
::
WriteConcern
&);
159
void
SetOption(
options
::
SuppressServerExceptions
);
160
161
private
:
162
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
163
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
164
165
class
Impl;
166
static
constexpr
size_t kSize = 88;
167
static
constexpr
size_t kAlignment = 8;
168
// MAC_COMPAT: std::string size differs
169
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
170
};
171
172
/// Replaces a single document
173
class
ReplaceOne
{
174
public
:
175
ReplaceOne(formats::
bson
::
Document
selector, formats::
bson
::
Document
replacement);
176
~ReplaceOne();
177
178
ReplaceOne(
const
ReplaceOne
&);
179
ReplaceOne(
ReplaceOne
&&)
noexcept
;
180
ReplaceOne
& operator=(
const
ReplaceOne
&);
181
ReplaceOne
& operator=(
ReplaceOne
&&)
noexcept
;
182
183
void
SetOption(
options
::
Upsert
);
184
void
SetOption(
options
::
WriteConcern
::
Level
);
185
void
SetOption(
const
options
::
WriteConcern
&);
186
void
SetOption(
options
::
SuppressServerExceptions
);
187
188
private
:
189
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
190
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
191
192
class
Impl;
193
static
constexpr
size_t kSize = 96;
194
static
constexpr
size_t kAlignment = 8;
195
// MAC_COMPAT: std::string size differs
196
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
197
};
198
199
/// Updates documents
200
class
Update
{
201
public
:
202
enum
class
Mode { kSingle, kMulti };
203
204
Update(Mode mode, formats::
bson
::
Document
selector, formats::
bson
::
Document
update);
205
~Update();
206
207
Update(
const
Update
&);
208
Update(
Update
&&)
noexcept
;
209
Update
& operator=(
const
Update
&);
210
Update
& operator=(
Update
&&)
noexcept
;
211
212
void
SetOption(
options
::
Upsert
);
213
void
SetOption(
options
::
RetryDuplicateKey
);
214
void
SetOption(
options
::
WriteConcern
::
Level
);
215
void
SetOption(
const
options
::
WriteConcern
&);
216
void
SetOption(
options
::
SuppressServerExceptions
);
217
void
SetOption(
const
options
::
ArrayFilters
&);
218
219
/// @note Available starting in MongoDB 4.2.1
220
void
SetOption
(
const
options
::
Hint
&);
221
222
private
:
223
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
224
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
225
226
class
Impl;
227
static
constexpr
size_t kSize = 96;
228
static
constexpr
size_t kAlignment = 8;
229
// MAC_COMPAT: std::string size differs
230
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
231
};
232
233
/// Deletes documents
234
class
Delete
{
235
public
:
236
enum
class
Mode { kSingle, kMulti };
237
238
Delete(Mode mode, formats::
bson
::
Document
selector);
239
~Delete();
240
241
Delete(
const
Delete
&);
242
Delete(
Delete
&&)
noexcept
;
243
Delete
& operator=(
const
Delete
&);
244
Delete
& operator=(
Delete
&&)
noexcept
;
245
246
void
SetOption(
options
::
WriteConcern
::
Level
);
247
void
SetOption(
const
options
::
WriteConcern
&);
248
void
SetOption(
options
::
SuppressServerExceptions
);
249
250
/// @note Available starting in MongoDB 4.4
251
void
SetOption
(
const
options
::
Hint
&);
252
253
private
:
254
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
255
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
256
257
class
Impl;
258
static
constexpr
size_t kSize = 80;
259
static
constexpr
size_t kAlignment = 8;
260
// MAC_COMPAT: std::string size differs
261
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
262
};
263
264
/// Atomically updates a document and returns either previous or new version
265
class
FindAndModify
{
266
public
:
267
FindAndModify(formats::
bson
::
Document
query,
const
formats::
bson
::
Document
& update);
268
~FindAndModify();
269
270
FindAndModify(
const
FindAndModify
&) =
delete
;
271
FindAndModify(
FindAndModify
&&)
noexcept
;
272
FindAndModify
& operator=(
const
FindAndModify
&) =
delete
;
273
FindAndModify
& operator=(
FindAndModify
&&)
noexcept
;
274
275
void
SetOption(
options
::
ReturnNew
);
276
void
SetOption(
options
::
Upsert
);
277
void
SetOption(
options
::
RetryDuplicateKey
);
278
void
SetOption(
const
options
::
Sort
&);
279
void
SetOption(
options
::
Projection
);
280
void
SetOption(
options
::
WriteConcern
::
Level
);
281
void
SetOption(
const
options
::
WriteConcern
&);
282
void
SetOption(
const
options
::
MaxServerTime
&);
283
void
SetOption(
const
options
::
ArrayFilters
&);
284
285
private
:
286
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
287
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
288
289
class
Impl;
290
FindAndModify(Impl&&);
291
static
constexpr
size_t kSize = 80;
292
static
constexpr
size_t kAlignment = 8;
293
// MAC_COMPAT: std::string size differs
294
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
295
};
296
297
/// Atomically removes a document and returns it
298
class
FindAndRemove
{
299
public
:
300
explicit
FindAndRemove(formats::
bson
::
Document
query);
301
~FindAndRemove();
302
303
FindAndRemove(
const
FindAndRemove
&) =
delete
;
304
FindAndRemove(
FindAndRemove
&&)
noexcept
;
305
FindAndRemove
& operator=(
const
FindAndRemove
&) =
delete
;
306
FindAndRemove
& operator=(
FindAndRemove
&&)
noexcept
;
307
308
void
SetOption(
const
options
::
Sort
&);
309
void
SetOption(
options
::
Projection
);
310
void
SetOption(
options
::
WriteConcern
::
Level
);
311
void
SetOption(
const
options
::
WriteConcern
&);
312
void
SetOption(
const
options
::
MaxServerTime
&);
313
314
private
:
315
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
316
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
317
318
class
Impl;
319
FindAndRemove(Impl&&);
320
static
constexpr
size_t kSize = 72;
321
static
constexpr
size_t kAlignment = 8;
322
// MAC_COMPAT: std::string size differs
323
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
324
};
325
326
/// Runs an aggregation pipeline
327
class
Aggregate
{
328
public
:
329
explicit
Aggregate(formats::
bson
::
Value
pipeline);
330
~Aggregate();
331
332
Aggregate(
const
Aggregate
&);
333
Aggregate(
Aggregate
&&)
noexcept
;
334
Aggregate
& operator=(
const
Aggregate
&);
335
Aggregate
& operator=(
Aggregate
&&)
noexcept
;
336
337
void
SetOption(
const
options
::
ReadPreference
&);
338
void
SetOption(
options
::
ReadPreference
::
Mode
);
339
void
SetOption(
options
::
ReadConcern
);
340
void
SetOption(
const
options
::
WriteConcern
&);
341
void
SetOption(
options
::
WriteConcern
::
Level
);
342
void
SetOption(
const
options
::
Hint
&);
343
void
SetOption(
const
options
::
Comment
&);
344
void
SetOption(
const
options
::
MaxServerTime
&);
345
346
private
:
347
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
348
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
349
350
class
Impl;
351
static
constexpr
size_t kSize = 120;
352
static
constexpr
size_t kAlignment = 8;
353
// MAC_COMPAT: std::string size differs
354
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
355
};
356
357
/// Retrieves distinct values for a specified field
358
class
Distinct
final
{
359
public
:
360
explicit
Distinct(std::string field);
361
Distinct(std::string field, formats::
bson
::
Document
filter);
362
~Distinct();
363
364
Distinct(
const
Distinct&);
365
Distinct(Distinct&&)
noexcept
;
366
Distinct& operator=(
const
Distinct&);
367
Distinct& operator=(Distinct&&)
noexcept
;
368
369
void
SetOption(
const
options
::
ReadPreference
&);
370
void
SetOption(
options
::
ReadPreference
::
Mode
);
371
void
SetOption(
options
::
ReadConcern
);
372
void
SetOption(
const
options
::Collation&);
373
void
SetOption(
const
options
::
Comment
&);
374
void
SetOption(
const
options
::
MaxServerTime
&);
375
376
private
:
377
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
378
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
379
380
class
Impl;
381
static
constexpr
size_t kSize = 104;
382
static
constexpr
size_t kAlignment = 8;
383
// MAC_COMPAT: std::string size differs
384
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
385
};
386
387
class
Drop
{
388
public
:
389
Drop();
390
~Drop();
391
392
Drop(
const
Drop
&);
393
Drop(
Drop
&&)
noexcept
;
394
Drop
& operator=(
const
Drop
&);
395
Drop
& operator=(
Drop
&&)
noexcept
;
396
397
void
SetOption(
const
options
::
WriteConcern
&);
398
void
SetOption(
options
::
WriteConcern
::
Level
);
399
400
private
:
401
friend
class
storages::mongo::impl::cdriver::CDriverCollectionImpl;
402
friend
class
storages::mongo::impl::cdriver::CDriverTransactionCollectionImpl;
403
404
class
Impl;
405
static
constexpr
size_t kSize = 56;
406
static
constexpr
size_t kAlignment = 8;
407
// MAC_COMPAT: std::string size differs
408
utils
::FastPimpl<Impl, kSize, kAlignment,
false
> impl_;
409
};
410
411
}
// namespace storages::mongo::operations
412
413
USERVER_NAMESPACE_END
userver
storages
mongo
operations.hpp
Generated on
for userver by
Doxygen
1.17.0