17 #include <mangrove/config/prelude.hpp> 21 #include <bsoncxx/builder/basic/document.hpp> 22 #include <bsoncxx/stdx/optional.hpp> 23 #include <mongocxx/collection.hpp> 25 #include <boson/mapping_functions.hpp> 26 #include <mangrove/deserializing_cursor.hpp> 29 MANGROVE_INLINE_NAMESPACE_BEGIN
73 template <
class Result = T>
75 const mongocxx::pipeline& pipeline,
76 const mongocxx::options::aggregate& options = mongocxx::options::aggregate()) {
96 bsoncxx::document::view_or_value filter,
97 const mongocxx::options::find& options = mongocxx::options::find()) {
115 bsoncxx::document::view_or_value filter,
116 const mongocxx::options::find& options = mongocxx::options::find()) {
117 return boson::to_optional_obj<T>(_coll.find_one(filter, options));
133 bsoncxx::document::view_or_value filter,
134 const mongocxx::options::find_one_and_delete& options =
135 mongocxx::options::find_one_and_delete()) {
136 return boson::to_optional_obj<T>(_coll.find_one_and_delete(filter, options));
159 bsoncxx::document::view_or_value filter,
const T& replacement,
160 const mongocxx::options::find_one_and_replace& options =
161 mongocxx::options::find_one_and_replace()) {
162 return boson::to_optional_obj<T>(
163 _coll.find_one_and_replace(filter, boson::to_document(replacement), options));
180 mongocxx::stdx::optional<mongocxx::result::insert_one>
insert_one(
181 T obj,
const mongocxx::options::insert& options = mongocxx::options::insert()) {
182 return _coll.insert_one(boson::to_document(obj), options);
207 template <
typename container_type>
208 mongocxx::stdx::optional<mongocxx::result::insert_many>
insert_many(
209 const container_type& container,
210 const mongocxx::options::insert& options = mongocxx::options::insert()) {
211 return insert_many(container.begin(), container.end(), options);
241 template <
typename object_iterator_type>
242 mongocxx::stdx::optional<mongocxx::result::insert_many>
insert_many(
243 object_iterator_type begin, object_iterator_type end,
244 const mongocxx::options::insert& options = mongocxx::options::insert()) {
264 mongocxx::stdx::optional<mongocxx::result::replace_one>
replace_one(
265 bsoncxx::document::view_or_value filter,
const T& replacement,
266 const mongocxx::options::update& options = mongocxx::options::update()) {
267 return _coll.replace_one(filter, boson::to_document(replacement), options);
271 mongocxx::collection _coll;
274 MANGROVE_INLINE_NAMESPACE_END
277 #include <mangrove/config/postlude.hpp> mongocxx::stdx::optional< T > find_one_and_replace(bsoncxx::document::view_or_value filter, const T &replacement, const mongocxx::options::find_one_and_replace &options=mongocxx::options::find_one_and_replace())
Finds a single document matching the filter, replaces it, and returns either the original or the repl...
Definition: collection_wrapper.hpp:158
mongocxx::stdx::optional< mongocxx::result::insert_many > insert_many(const container_type &container, const mongocxx::options::insert &options=mongocxx::options::insert())
Inserts multiple serializable objects into the collection.
Definition: collection_wrapper.hpp:208
mongocxx::stdx::optional< mongocxx::result::replace_one > replace_one(bsoncxx::document::view_or_value filter, const T &replacement, const mongocxx::options::update &options=mongocxx::options::update())
Replaces a single document matching the provided filter in this collection.
Definition: collection_wrapper.hpp:264
A class that wraps a mongocxx::cursor.
Definition: deserializing_cursor.hpp:37
An iterator that wraps another iterator of serializable objects, and yields BSON document views corre...
Definition: mapping_functions.hpp:129
mongocxx::stdx::optional< T > find_one(bsoncxx::document::view_or_value filter, const mongocxx::options::find &options=mongocxx::options::find())
Finds a single document in this collection that match the provided filter.
Definition: collection_wrapper.hpp:114
mongocxx::stdx::optional< T > find_one_and_delete(bsoncxx::document::view_or_value filter, const mongocxx::options::find_one_and_delete &options=mongocxx::options::find_one_and_delete())
Finds a single document matching the filter, deletes it, and returns the original as a deserialized o...
Definition: collection_wrapper.hpp:132
mongocxx::stdx::optional< mongocxx::result::insert_many > insert_many(object_iterator_type begin, object_iterator_type end, const mongocxx::options::insert &options=mongocxx::options::insert())
Inserts multiple serializable objects into the collection.
Definition: collection_wrapper.hpp:242
Definition: collection_wrapper.hpp:28
Definition: collection_wrapper.hpp:32
deserializing_cursor< Result > aggregate(const mongocxx::pipeline &pipeline, const mongocxx::options::aggregate &options=mongocxx::options::aggregate())
Runs an aggregation framework pipeline against this collection, and returns the results as de-seriali...
Definition: collection_wrapper.hpp:74
deserializing_cursor< T > find(bsoncxx::document::view_or_value filter, const mongocxx::options::find &options=mongocxx::options::find())
Finds the documents in this collection which match the provided filter.
Definition: collection_wrapper.hpp:95
mongocxx::stdx::optional< mongocxx::result::insert_one > insert_one(T obj, const mongocxx::options::insert &options=mongocxx::options::insert())
Inserts a single serializable object into the collection.
Definition: collection_wrapper.hpp:180
mongocxx::collection collection()
Returns a copy of the underlying collection.
Definition: collection_wrapper.hpp:50