12#include <userver/formats/bson/document.hpp>
13#include <userver/formats/bson/value.hpp>
14#include <userver/storages/mongo/bulk.hpp>
15#include <userver/storages/mongo/cursor.hpp>
16#include <userver/storages/mongo/operations.hpp>
17#include <userver/storages/mongo/write_result.hpp>
19USERVER_NAMESPACE_BEGIN
21namespace storages::mongo {
38 explicit Collection(std::shared_ptr<impl::CollectionImpl>);
44 template <
typename... Options>
49 template <
typename... Options>
53 template <
typename... Options>
57 template <
typename... Options>
61 template <
typename... Options>
65 template <
typename... Options>
70 template <
typename... Options>
75 template <
typename... Options>
80 template <
typename... Options>
84 template <
typename... Options>
88 template <
typename... Options>
94 template <
typename... Options>
99 template <
typename... Options>
103 template <
typename... Options>
104 void Drop(Options&&... options);
107 template <
typename... Options>
111 template <
typename... Options>
116 template <
typename... Options>
124 size_t Execute(
const operations::Count&)
const;
125 size_t Execute(
const operations::CountApprox&)
const;
139 std::shared_ptr<impl::CollectionImpl> impl_;
142template <
typename... Options>
145 (count_op.SetOption(std::forward<Options>(options)), ...);
146 return Execute(count_op);
149template <
typename... Options>
152 (count_approx_op.SetOption(std::forward<Options>(options)), ...);
153 return Execute(count_approx_op);
158template <
typename Option,
typename... Options>
159using HasOptionHelper = std::disjunction<std::is_same<std::decay_t<Options>, Option>...>;
161template <
typename Option,
typename... Options>
162static constexpr bool kHasOption = HasOptionHelper<Option, Options...>::value;
166template <
typename... Options>
169 (find_op.SetOption(std::forward<Options>(options)), ...);
170 return Execute(find_op);
173template <
typename... Options>
176 !(std::is_same<std::decay_t<Options>, options::Limit>::value || ...),
"Limit option cannot be used in FindOne"
178 auto cursor = Find(std::move(filter), options::Limit{1}, std::forward<Options>(options)...);
179 if (cursor.begin() == cursor.end())
return {};
180 return *cursor.begin();
183template <
typename... Options>
186 (insert_op.SetOption(std::forward<Options>(options)), ...);
187 return Execute(insert_op);
190template <
typename... Options>
193 (insert_op.SetOption(std::forward<Options>(options)), ...);
194 return Execute(insert_op);
197template <
typename... Options>
201 (replace_op.SetOption(std::forward<Options>(options)), ...);
202 return Execute(replace_op);
205template <
typename... Options>
209 (update_op.SetOption(std::forward<Options>(options)), ...);
210 return Execute(update_op);
213template <
typename... Options>
217 (update_op.SetOption(std::forward<Options>(options)), ...);
218 return Execute(update_op);
221template <
typename... Options>
224 (delete_op.SetOption(std::forward<Options>(options)), ...);
225 return Execute(delete_op);
228template <
typename... Options>
231 (delete_op.SetOption(std::forward<Options>(options)), ...);
232 return Execute(delete_op);
235template <
typename... Options>
239 (fam_op.SetOption(std::forward<Options>(options)), ...);
240 return Execute(fam_op);
243template <
typename... Options>
246 (fam_op.SetOption(std::forward<Options>(options)), ...);
247 return Execute(fam_op);
250template <
typename... Options>
253 (drop_op.SetOption(std::forward<Options>(options)), ...);
254 return Execute(drop_op);
257template <
typename... Options>
260 (bulk.SetOption(std::forward<Options>(options)), ...);
264template <
typename... Options>
267 (bulk.SetOption(std::forward<Options>(options)), ...);
271template <
typename... Options>
274 (aggregate.SetOption(std::forward<Options>(options)), ...);
275 return Execute(aggregate);