Mangrove
The C++ Object Document Mapper for MongoDB
Public Member Functions | List of all members
mangrove::collection_wrapper< T > Class Template Reference

Public Member Functions

mongocxx::collection collection ()
 Returns a copy of the underlying collection. More...
 
template<class Result = T>
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-serialized objects. More...
 
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. More...
 
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. More...
 
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 object. More...
 
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 replacement document as a deserialized object. More...
 
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. More...
 
template<typename container_type >
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. More...
 
template<typename object_iterator_type >
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. More...
 
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. More...
 

Member Function Documentation

template<class T>
template<class Result = T>
deserializing_cursor<Result> mangrove::collection_wrapper< T >::aggregate ( const mongocxx::pipeline &  pipeline,
const mongocxx::options::aggregate &  options = mongocxx::options::aggregate() 
)
inline

Runs an aggregation framework pipeline against this collection, and returns the results as de-serialized objects.

This function is templated on the result's type, which is not necessarily the same as the type of the documents in the colleciton.

Template Parameters
Result- The type of the aggregation result.
Parameters
pipelineThe pipeline of aggregation operations to perform.
optionsOptional arguments, see mongocxx::mongocxx::options::aggregate.
Returns
A deserializing_cursor<Result> with the results.
Exceptions
Ifthe operation failed, the returned cursor will throw an mongocxx::exception::query when it is iterated.
See also
http://docs.mongodb.org/manual/reference/command/aggregate/
template<class T>
mongocxx::collection mangrove::collection_wrapper< T >::collection ( )
inline

Returns a copy of the underlying collection.

Returns
The mongocxx::collection that this object wraps
template<class T>
deserializing_cursor<T> mangrove::collection_wrapper< T >::find ( bsoncxx::document::view_or_value  filter,
const mongocxx::options::find &  options = mongocxx::options::find() 
)
inline

Finds the documents in this collection which match the provided filter.

Parameters
filterDocument view representing a document that should match the query.
optionsOptional arguments, see mongocxx::options::find
Returns
Cursor with deserialized objects from the collection.
Exceptions
Ifthe find failed, the returned cursor will throw mongocxx::exception::query when it is iterated.
See also
http://docs.mongodb.org/manual/core/read-operations-introduction/
template<class T>
mongocxx::stdx::optional<T> mangrove::collection_wrapper< T >::find_one ( bsoncxx::document::view_or_value  filter,
const mongocxx::options::find &  options = mongocxx::options::find() 
)
inline

Finds a single document in this collection that match the provided filter.

Parameters
filterDocument view representing a document that should match the query.
optionsOptional arguments, see mongocxx::options::find
Returns
An optional object that matched the filter.
Exceptions
mongocxx::exception::queryif the operation fails.
See also
http://docs.mongodb.org/manual/core/read-operations-introduction/
template<class T>
mongocxx::stdx::optional<T> mangrove::collection_wrapper< 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() 
)
inline

Finds a single document matching the filter, deletes it, and returns the original as a deserialized object.

Parameters
filterDocument view representing a document that should be deleted.
optionsOptional arguments, see mongocxx::options::find_one_and_delete
Returns
The deserialized object that was deleted from the database.
Exceptions
mongocxx::exception::writeif the operation fails.
template<class T>
mongocxx::stdx::optional<T> mangrove::collection_wrapper< 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() 
)
inline

Finds a single document matching the filter, replaces it, and returns either the original or the replacement document as a deserialized object.

Parameters
filterDocument view representing a document that should be replaced.
replacementSerializable object representing the replacement for a matching document.
optionsOptional arguments, see mongocxx::options::find_one_and_replace.
Returns
The original or replaced object.
Exceptions
mongocxx::exception::writeif the operation fails.
Note
In order to pass a write concern to this, you must use the collection level set write concern - collection::write_concern(wc).
template<class T>
template<typename container_type >
mongocxx::stdx::optional<mongocxx::result::insert_many> mangrove::collection_wrapper< T >::insert_many ( const container_type &  container,
const mongocxx::options::insert &  options = mongocxx::options::insert() 
)
inline

Inserts multiple serializable objects into the collection.

// TODO how to deal w/ identifiers If any of the are missing identifiers the driver will generate them.

Warning
This method uses the bulk insert command to execute the insertion as opposed to the legacy OP_INSERT wire protocol message. As a result, using this method to insert many documents on MongoDB < 2.6 will be slow.
Template Parameters
containter_typeThe container type. Must contain an iterator that yields serializable objects.
Parameters
containerContainer of serializable objects to insert.
optionsOptional arguments, see mongocxx::options::insert.
Returns
The result of attempting to performing the insert.
Exceptions
mongocxx::exception::writewhen the operation fails.
template<class T>
template<typename object_iterator_type >
mongocxx::stdx::optional<mongocxx::result::insert_many> mangrove::collection_wrapper< T >::insert_many ( object_iterator_type  begin,
object_iterator_type  end,
const mongocxx::options::insert &  options = mongocxx::options::insert() 
)
inline

Inserts multiple serializable objects into the collection.

TODO how to deal w/ identifiers If any of the documents are missing /// identifiers the driver will generate them.

Warning
This method uses the bulk insert command to execute the insertion as opposed to the legacy OP_INSERT wire protocol message. As a result, using this method to insert many documents on MongoDB < 2.6 will be slow.
Template Parameters
object_iterator_typeThe iterator type. Must meet the requirements for the input iterator concept with a value type that is a serializable object.
Parameters
beginIterator pointing to the first document to be inserted.
endIterator pointing to the end of the documents to be inserted.
optionsOptional arguments, see mongocxx::options::insert.
Returns
The result of attempting to performing the insert.
Exceptions
mongocxx::exception::writeif the operation fails.

TODO: document DocumentViewIterator concept or static assert

template<class T>
mongocxx::stdx::optional<mongocxx::result::insert_one> mangrove::collection_wrapper< T >::insert_one ( obj,
const mongocxx::options::insert &  options = mongocxx::options::insert() 
)
inline

Inserts a single serializable object into the collection.

// TODO how to deal w/ identifiers If the document is missing an identifier (_id field) one will be generated for it.

Parameters
documentThe document to insert.
optionsOptional arguments, see mongocxx::options::insert.
Returns
The result of attempting to perform the insert.
Exceptions
mongocxx::exception::writeif the operation fails.
template<class T>
mongocxx::stdx::optional<mongocxx::result::replace_one> mangrove::collection_wrapper< T >::replace_one ( bsoncxx::document::view_or_value  filter,
const T &  replacement,
const mongocxx::options::update &  options = mongocxx::options::update() 
)
inline

Replaces a single document matching the provided filter in this collection.

Parameters
filterDocument representing the match criteria.
replacementThe replacement document, as a serializable object.
optionsOptional arguments, see mongocxx::options::update.
Returns
The result of attempting to replace a document.
Exceptions
mongocxx::exception::writeif the operation fails.
See also
http://docs.mongodb.org/manual/reference/command/update/

The documentation for this class was generated from the following file: