12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054 |
- // Copyright 2014-present MongoDB Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- #pragma once
- #include <algorithm>
- #include <bsoncxx/builder/basic/array.hpp>
- #include <bsoncxx/builder/basic/document.hpp>
- #include <bsoncxx/builder/basic/kvp.hpp>
- #include <bsoncxx/builder/concatenate.hpp>
- #include <bsoncxx/document/view_or_value.hpp>
- #include <bsoncxx/oid.hpp>
- #include <bsoncxx/stdx/optional.hpp>
- #include <bsoncxx/string/view_or_value.hpp>
- #include <mongocxx/bulk_write.hpp>
- #include <mongocxx/change_stream.hpp>
- #include <mongocxx/client_session.hpp>
- #include <mongocxx/config/prelude.hpp>
- #include <mongocxx/cursor.hpp>
- #include <mongocxx/index_view.hpp>
- #include <mongocxx/model/insert_one.hpp>
- #include <mongocxx/options/aggregate.hpp>
- #include <mongocxx/options/bulk_write.hpp>
- #include <mongocxx/options/change_stream.hpp>
- #include <mongocxx/options/count.hpp>
- #include <mongocxx/options/delete.hpp>
- #include <mongocxx/options/distinct.hpp>
- #include <mongocxx/options/estimated_document_count.hpp>
- #include <mongocxx/options/find.hpp>
- #include <mongocxx/options/find_one_and_delete.hpp>
- #include <mongocxx/options/find_one_and_replace.hpp>
- #include <mongocxx/options/find_one_and_update.hpp>
- #include <mongocxx/options/index.hpp>
- #include <mongocxx/options/index_view.hpp>
- #include <mongocxx/options/insert.hpp>
- #include <mongocxx/options/replace.hpp>
- #include <mongocxx/options/update.hpp>
- #include <mongocxx/pipeline.hpp>
- #include <mongocxx/read_concern.hpp>
- #include <mongocxx/read_preference.hpp>
- #include <mongocxx/result/bulk_write.hpp>
- #include <mongocxx/result/delete.hpp>
- #include <mongocxx/result/insert_many.hpp>
- #include <mongocxx/result/insert_one.hpp>
- #include <mongocxx/result/replace_one.hpp>
- #include <mongocxx/result/update.hpp>
- #include <mongocxx/write_concern.hpp>
- #include <string>
- namespace mongocxx {
- MONGOCXX_INLINE_NAMESPACE_BEGIN
- class client;
- class database;
- ///
- /// Class representing server side document groupings within a MongoDB database.
- ///
- /// Collections do not require or enforce a schema and documents inside of a collection can have
- /// different fields. While not a requirement, typically documents in a collection have a similar
- /// shape or related purpose.
- ///
- /// Example:
- /// @code
- /// // Connect and get a collection.
- /// mongocxx::client mongo_client{mongocxx::uri{}};
- /// auto coll = mongo_client["database"]["collection"];
- /// @endcode
- ///
- class MONGOCXX_API collection {
- //
- // Utility class supporting the convenience of {} meaning an empty bsoncxx::document.
- //
- // Users may not use this class directly.
- //
- // In places where driver methods take this class as a parameter, passing {} will
- // translate to a default-constructed bsoncxx::document::view_or_value,
- // regardless of other overloads taking other default-constructible types
- // for that parameter. This class avoids compiler ambiguity with such overloads.
- //
- // See collection::update_one for an example of such overloads.
- //
- class _empty_doc_tag {
- _empty_doc_tag() = default;
- };
- public:
- ///
- /// Default constructs a collection object. The collection is
- /// equivalent to the state of a moved from collection. The only
- /// valid actions to take with a default constructed collection
- /// are to assign to it, or destroy it.
- ///
- collection() noexcept;
- ///
- /// Move constructs a collection.
- ///
- collection(collection&&) noexcept;
- ///
- /// Move assigns a collection.
- ///
- collection& operator=(collection&&) noexcept;
- ///
- /// Copy constructs a collection.
- ///
- collection(const collection&);
- ///
- /// Copy assigns a collection.
- ///
- collection& operator=(const collection&);
- ///
- /// Destroys a collection.
- ///
- ~collection();
- ///
- /// Returns true if the collection is valid, meaning it was not
- /// default constructed or moved from.
- ///
- explicit operator bool() const noexcept;
- ///
- /// @{
- ///
- /// Runs an aggregation framework pipeline against this collection.
- ///
- /// @param pipeline
- /// The pipeline of aggregation operations to perform.
- /// @param options
- /// Optional arguments, see mongocxx::options::aggregate.
- ///
- /// @return A mongocxx::cursor with the results. If the query fails,
- /// the cursor throws mongocxx::query_exception when the returned cursor
- /// is iterated.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/aggregate/
- ///
- /// @note
- /// In order to pass a read concern to this, you must use the
- /// collection level set read concern - collection::read_concern(rc).
- /// (Write concern supported only for MongoDB 3.4+).
- ///
- cursor aggregate(const pipeline& pipeline,
- const options::aggregate& options = options::aggregate());
- ///
- /// Runs an aggregation framework pipeline against this collection.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the aggregation.
- /// @param pipeline
- /// The pipeline of aggregation operations to perform.
- /// @param options
- /// Optional arguments, see mongocxx::options::aggregate.
- ///
- /// @return A mongocxx::cursor with the results. If the query fails,
- /// the cursor throws mongocxx::query_exception when the returned cursor
- /// is iterated.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/aggregate/
- ///
- /// @note
- /// In order to pass a read concern to this, you must use the
- /// collection level set read concern - collection::read_concern(rc).
- /// (Write concern supported only for MongoDB 3.4+).
- ///
- cursor aggregate(const client_session& session,
- const pipeline& pipeline,
- const options::aggregate& options = options::aggregate());
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Creates a new bulk operation to be executed against this collection.
- /// The lifetime of the bulk_write is independent of the collection.
- ///
- /// @param options
- /// Optional arguments; see mongocxx::options::bulk_write.
- ///
- /// @return
- /// The newly-created bulk write.
- ///
- class bulk_write create_bulk_write(const options::bulk_write& options = {});
- ///
- /// Creates a new bulk operation to be executed against this collection.
- /// The lifetime of the bulk_write is independent of the collection.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the bulk operation.
- /// @param options
- /// Optional arguments; see mongocxx::options::bulk_write.
- ///
- /// @return
- /// The newly-created bulk write.
- ///
- class bulk_write create_bulk_write(const client_session& session,
- const options::bulk_write& options = {});
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Sends a write to the server as a bulk write operation.
- ///
- /// @param write
- /// A model::write.
- /// @param options
- /// Optional arguments, see options::bulk_write.
- ///
- /// @return
- /// The optional result of the bulk operation execution.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @exception
- /// mongocxx::bulk_write_exception when there are errors processing
- /// the writes.
- ///
- /// @see mongocxx::bulk_write
- /// @see https://docs.mongodb.com/master/core/bulk-write-operations/
- ///
- MONGOCXX_INLINE stdx::optional<result::bulk_write> write(
- const model::write& write, const options::bulk_write& options = options::bulk_write());
- ///
- /// Sends a write to the server as a bulk write operation.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the bulk operation.
- /// @param write
- /// A model::write.
- /// @param options
- /// Optional arguments, see options::bulk_write.
- ///
- /// @return
- /// The optional result of the bulk operation execution.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @exception
- /// mongocxx::bulk_write_exception when there are errors processing
- /// the writes.
- ///
- /// @see mongocxx::bulk_write
- /// @see https://docs.mongodb.com/master/core/bulk-write-operations/
- ///
- MONGOCXX_INLINE stdx::optional<result::bulk_write> write(
- const client_session& session,
- const model::write& write,
- const options::bulk_write& options = options::bulk_write());
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Sends a container of writes to the server as a bulk write operation.
- ///
- /// @tparam container_type
- /// The container type. Must meet the requirements for the container concept with a value
- /// type of model::write.
- ///
- /// @param writes
- /// A container of model::write.
- /// @param options
- /// Optional arguments, see options::bulk_write.
- ///
- /// @return The optional result of the bulk operation execution.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws mongocxx::bulk_write_exception when there are errors processing the writes.
- ///
- /// @see mongocxx::bulk_write
- /// @see https://docs.mongodb.com/master/core/bulk-write-operations/
- ///
- template <typename container_type>
- MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
- const container_type& writes, const options::bulk_write& options = options::bulk_write());
- ///
- /// Sends a container of writes to the server as a bulk write operation.
- ///
- /// @tparam container_type
- /// The container type. Must meet the requirements for the container concept with a value
- /// type of model::write.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the bulk operation.
- /// @param writes
- /// A container of model::write.
- /// @param options
- /// Optional arguments, see options::bulk_write.
- ///
- /// @return The optional result of the bulk operation execution.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws mongocxx::bulk_write_exception when there are errors processing the writes.
- ///
- /// @see mongocxx::bulk_write
- /// @see https://docs.mongodb.com/master/core/bulk-write-operations/
- ///
- template <typename container_type>
- MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
- const client_session& session,
- const container_type& writes,
- const options::bulk_write& options = options::bulk_write());
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Sends writes starting at @c begin and ending at @c end to the server as a bulk write
- /// operation.
- ///
- /// @tparam write_model_iterator_type
- /// The container type. Must meet the requirements for the input iterator concept with a value
- /// type of model::write.
- ///
- /// @param begin
- /// Iterator pointing to the first model::write to send.
- /// @param end
- /// Iterator pointing to the end of the writes to send.
- /// @param options
- /// Optional arguments, see options::bulk_write.
- ///
- /// @return The optional result of the bulk operation execution, a result::bulk_write.
- ///
- /// @throws mongocxx::bulk_write_exception when there are errors processing the writes.
- ///
- /// @see mongocxx::bulk_write
- /// @see https://docs.mongodb.com/master/core/bulk-write-operations/
- ///
- template <typename write_model_iterator_type>
- MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
- write_model_iterator_type begin,
- write_model_iterator_type end,
- const options::bulk_write& options = options::bulk_write());
- ///
- /// Sends writes starting at @c begin and ending at @c end to the server as a bulk write
- /// operation.
- ///
- /// @tparam write_model_iterator_type
- /// The container type. Must meet the requirements for the input iterator concept with a value
- /// type of model::write.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the bulk operation.
- /// @param begin
- /// Iterator pointing to the first model::write to send.
- /// @param end
- /// Iterator pointing to the end of the writes to send.
- /// @param options
- /// Optional arguments, see options::bulk_write.
- ///
- /// @return The optional result of the bulk operation execution, a result::bulk_write.
- ///
- /// @throws mongocxx::bulk_write_exception when there are errors processing the writes.
- ///
- /// @see mongocxx::bulk_write
- /// @see https://docs.mongodb.com/master/core/bulk-write-operations/
- ///
- template <typename write_model_iterator_type>
- MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
- const client_session& session,
- write_model_iterator_type begin,
- write_model_iterator_type end,
- const options::bulk_write& options = options::bulk_write());
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Counts the number of documents matching the provided filter.
- ///
- /// @param filter
- /// The filter that documents must match in order to be counted.
- /// @param options
- /// Optional arguments, see mongocxx::options::count.
- ///
- /// @return The count of the documents that matched the filter.
- ///
- /// @throws mongocxx::query_exception if the count operation fails.
- ///
- std::int64_t count_documents(bsoncxx::document::view_or_value filter,
- const options::count& options = options::count());
- ///
- /// Counts the number of documents matching the provided filter.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the count.
- /// @param filter
- /// The filter that documents must match in order to be counted.
- /// @param options
- /// Optional arguments, see mongocxx::options::count.
- ///
- /// @return The count of the documents that matched the filter.
- ///
- /// @throws mongocxx::query_exception if the count operation fails.
- ///
- std::int64_t count_documents(const client_session& session,
- bsoncxx::document::view_or_value filter,
- const options::count& options = options::count());
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Returns an estimate of the number of documents in the collection.
- ///
- /// @param options
- /// Optional arguments, see mongocxx::options::count.
- ///
- /// @return The count of the documents that matched the filter.
- ///
- /// @throws mongocxx::query_exception if the count operation fails.
- ///
- std::int64_t estimated_document_count(
- const options::estimated_document_count& options = options::estimated_document_count());
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Creates an index over the collection for the provided keys with the provided options.
- ///
- /// @param keys
- /// The keys for the index: @c {a: 1, b: -1}
- /// @param index_options
- /// A document containing optional arguments for creating the index.
- /// @param operation_options
- /// Optional arguments for the overall operation, see mongocxx::options::index_view.
- ///
- /// @exception
- /// mongocxx::operation_exception if index creation fails.
- ///
- /// @see
- /// https://docs.mongodb.com/master/reference/command/createIndexes/
- ///
- /// @note
- /// Write concern supported only for MongoDB 3.4+.
- ///
- bsoncxx::document::value create_index(
- bsoncxx::document::view_or_value keys,
- bsoncxx::document::view_or_value index_options = {},
- options::index_view operation_options = options::index_view{});
- ///
- /// Creates an index over the collection for the provided keys with the provided options.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the index creation.
- /// @param keys
- /// The keys for the index: @c {a: 1, b: -1}
- /// @param index_options
- /// A document containing optional arguments for creating the index.
- /// @param operation_options
- /// Optional arguments for the overall operation, see mongocxx::options::index_view.
- ///
- /// @exception
- /// mongocxx::operation_exception if index creation fails.
- ///
- /// @see
- /// https://docs.mongodb.com/master/reference/command/createIndexes/
- ///
- /// @note
- /// Write concern supported only for MongoDB 3.4+.
- ///
- bsoncxx::document::value create_index(
- const client_session& session,
- bsoncxx::document::view_or_value keys,
- bsoncxx::document::view_or_value index_options = {},
- options::index_view operation_options = options::index_view{});
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Deletes all matching documents from the collection.
- ///
- /// @param filter
- /// Document view representing the data to be deleted.
- /// @param options
- /// Optional arguments, see mongocxx::options::delete_options.
- ///
- /// @return The optional result of performing the deletion.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws mongocxx::bulk_write_exception if the delete fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/delete/
- ///
- stdx::optional<result::delete_result> delete_many(
- bsoncxx::document::view_or_value filter,
- const options::delete_options& options = options::delete_options());
- ///
- /// Deletes all matching documents from the collection.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the deletion.
- /// @param filter
- /// Document view representing the data to be deleted.
- /// @param options
- /// Optional arguments, see mongocxx::options::delete_options.
- ///
- /// @return The optional result of performing the deletion.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws mongocxx::bulk_write_exception if the delete fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/delete/
- ///
- stdx::optional<result::delete_result> delete_many(
- const client_session& session,
- bsoncxx::document::view_or_value filter,
- const options::delete_options& options = options::delete_options());
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Deletes a single matching document from the collection.
- ///
- /// @param filter
- /// Document view representing the data to be deleted.
- /// @param options
- /// Optional arguments, see mongocxx::options::delete_options.
- ///
- /// @return The optional result of performing the deletion.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws mongocxx::bulk_write_exception if the delete fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/delete/
- ///
- stdx::optional<result::delete_result> delete_one(
- bsoncxx::document::view_or_value filter,
- const options::delete_options& options = options::delete_options());
- ///
- /// Deletes a single matching document from the collection.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the deletion.
- /// @param filter
- /// Document view representing the data to be deleted.
- /// @param options
- /// Optional arguments, see mongocxx::options::delete_options.
- ///
- /// @return The optional result of performing the deletion.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws mongocxx::bulk_write_exception if the delete fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/delete/
- ///
- stdx::optional<result::delete_result> delete_one(
- const client_session& session,
- bsoncxx::document::view_or_value filter,
- const options::delete_options& options = options::delete_options());
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Finds the distinct values for a specified field across the collection.
- ///
- /// @param name
- /// The field for which the distinct values will be found.
- /// @param filter
- /// Document view representing the documents for which the distinct operation will apply.
- /// @param options
- /// Optional arguments, see options::distinct.
- /// @return mongocxx::cursor having the distinct values for the specified
- /// field. If the operation fails, the cursor throws
- /// mongocxx::query_exception when the returned cursor is iterated.
- /// @see https://docs.mongodb.com/master/reference/command/distinct/
- ///
- cursor distinct(bsoncxx::string::view_or_value name,
- bsoncxx::document::view_or_value filter,
- const options::distinct& options = options::distinct());
- ///
- /// Finds the distinct values for a specified field across the collection.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the operation.
- /// @param name
- /// The field for which the distinct values will be found.
- /// @param filter
- /// Document view representing the documents for which the distinct operation will apply.
- /// @param options
- /// Optional arguments, see options::distinct.
- /// @return mongocxx::cursor having the distinct values for the specified
- /// field. If the operation fails, the cursor throws
- /// mongocxx::query_exception when the returned cursor is iterated.
- /// @see https://docs.mongodb.com/master/reference/command/distinct/
- ///
- cursor distinct(const client_session& session,
- bsoncxx::string::view_or_value name,
- bsoncxx::document::view_or_value filter,
- const options::distinct& options = options::distinct());
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Drops this collection and all its contained documents from the database.
- ///
- /// @param write_concern (optional)
- /// The write concern to use for this operation. Defaults to the collection wide write
- /// concern if none is provided.
- ///
- /// @exception
- /// mongocxx::operation_exception if the operation fails.
- ///
- /// @see
- /// https://docs.mongodb.com/master/reference/command/drop/
- ///
- /// @note
- /// Write concern supported only for MongoDB 3.4+.
- ///
- void drop(const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {});
- ///
- /// Drops this collection and all its contained documents from the database.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the drop.
- /// @param write_concern (optional)
- /// The write concern to use for this operation. Defaults to the collection wide write
- /// concern if none is provided.
- ///
- /// @exception
- /// mongocxx::operation_exception if the operation fails.
- ///
- /// @see
- /// https://docs.mongodb.com/master/reference/command/drop/
- ///
- /// @note
- /// Write concern supported only for MongoDB 3.4+.
- ///
- void drop(const client_session& session,
- const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {});
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Finds the documents in this collection which match the provided filter.
- ///
- /// @param filter
- /// Document view representing a document that should match the query.
- /// @param options
- /// Optional arguments, see options::find
- ///
- /// @return A mongocxx::cursor with the results. If the query fails,
- /// the cursor throws mongocxx::query_exception when the returned cursor
- /// is iterated.
- ///
- /// @throws mongocxx::logic_error if the options are invalid, or if the unsupported option
- /// modifiers "$query" or "$explain" are used.
- ///
- /// @see https://docs.mongodb.com/master/core/read-operations-introduction/
- ///
- cursor find(bsoncxx::document::view_or_value filter,
- const options::find& options = options::find());
- ///
- /// Finds the documents in this collection which match the provided filter.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the query.
- /// @param filter
- /// Document view representing a document that should match the query.
- /// @param options
- /// Optional arguments, see options::find
- ///
- /// @return A mongocxx::cursor with the results. If the query fails,
- /// the cursor throws mongocxx::query_exception when the returned cursor
- /// is iterated.
- ///
- /// @throws mongocxx::logic_error if the options are invalid, or if the unsupported option
- /// modifiers "$query" or "$explain" are used.
- ///
- /// @see https://docs.mongodb.com/master/core/read-operations-introduction/
- ///
- cursor find(const client_session& session,
- bsoncxx::document::view_or_value filter,
- const options::find& options = options::find());
- ///
- /// @{
- ///
- /// Finds a single document in this collection that match the provided filter.
- ///
- /// @param filter
- /// Document view representing a document that should match the query.
- /// @param options
- /// Optional arguments, see options::find
- ///
- /// @return An optional document that matched the filter.
- ///
- /// @throws mongocxx::query_exception if the operation fails.
- ///
- /// @see https://docs.mongodb.com/master/core/read-operations-introduction/
- ///
- stdx::optional<bsoncxx::document::value> find_one(
- bsoncxx::document::view_or_value filter, const options::find& options = options::find());
- ///
- /// Finds a single document in this collection that match the provided filter.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the query.
- /// @param filter
- /// Document view representing a document that should match the query.
- /// @param options
- /// Optional arguments, see options::find
- ///
- /// @return An optional document that matched the filter.
- ///
- /// @throws mongocxx::query_exception if the operation fails.
- ///
- /// @see https://docs.mongodb.com/master/core/read-operations-introduction/
- ///
- stdx::optional<bsoncxx::document::value> find_one(
- const client_session& session,
- bsoncxx::document::view_or_value filter,
- const options::find& options = options::find());
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Finds a single document matching the filter, deletes it, and returns the original.
- ///
- /// @param filter
- /// Document view representing a document that should be deleted.
- /// @param options
- /// Optional arguments, see options::find_one_and_delete
- ///
- /// @return The document that was deleted.
- ///
- /// @exception
- /// Throws mongocxx::logic_error if the collation option is specified and an unacknowledged
- /// write concern is used.
- ///
- /// @exception
- /// Throws mongocxx::write_exception if the operation fails.
- ///
- stdx::optional<bsoncxx::document::value> find_one_and_delete(
- bsoncxx::document::view_or_value filter,
- const options::find_one_and_delete& options = options::find_one_and_delete());
- ///
- /// Finds a single document matching the filter, deletes it, and returns the original.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the operation.
- /// @param filter
- /// Document view representing a document that should be deleted.
- /// @param options
- /// Optional arguments, see options::find_one_and_delete
- ///
- /// @return The document that was deleted.
- ///
- /// @exception
- /// Throws mongocxx::logic_error if the collation option is specified and an unacknowledged
- /// write concern is used.
- ///
- /// @exception
- /// Throws mongocxx::write_exception if the operation fails.
- ///
- stdx::optional<bsoncxx::document::value> find_one_and_delete(
- const client_session& session,
- bsoncxx::document::view_or_value filter,
- const options::find_one_and_delete& options = options::find_one_and_delete());
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Finds a single document matching the filter, replaces it, and returns either the original
- /// or the replacement document.
- ///
- /// @param filter
- /// Document view representing a document that should be replaced.
- /// @param replacement
- /// Document view representing the replacement for a matching document.
- /// @param options
- /// Optional arguments, see options::find_one_and_replace.
- ///
- /// @return The original or replaced document.
- ///
- /// @exception
- /// Throws mongocxx::logic_error if the collation option is specified and an unacknowledged
- /// write concern is used.
- ///
- /// @exception
- /// Throws mongocxx::write_exception if the operation fails.
- ///
- stdx::optional<bsoncxx::document::value> find_one_and_replace(
- bsoncxx::document::view_or_value filter,
- bsoncxx::document::view_or_value replacement,
- const options::find_one_and_replace& options = options::find_one_and_replace());
- ///
- /// Finds a single document matching the filter, replaces it, and returns either the original
- /// or the replacement document.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the operation.
- /// @param filter
- /// Document view representing a document that should be replaced.
- /// @param replacement
- /// Document view representing the replacement for a matching document.
- /// @param options
- /// Optional arguments, see options::find_one_and_replace.
- ///
- /// @return The original or replaced document.
- ///
- /// @exception
- /// Throws mongocxx::logic_error if the collation option is specified and an unacknowledged
- /// write concern is used.
- ///
- /// @exception
- /// Throws mongocxx::write_exception if the operation fails.
- ///
- stdx::optional<bsoncxx::document::value> find_one_and_replace(
- const client_session& session,
- bsoncxx::document::view_or_value filter,
- bsoncxx::document::view_or_value replacement,
- const options::find_one_and_replace& options = options::find_one_and_replace());
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Finds a single document matching the filter, updates it, and returns either the original
- /// or the newly-updated document.
- ///
- /// @param filter
- /// Document view representing a document that should be updated.
- /// @param update
- /// Document view representing the update to apply to a matching document.
- /// @param options
- /// Optional arguments, see options::find_one_and_update.
- ///
- /// @return The original or updated document.
- ///
- /// @exception
- /// Throws mongocxx::logic_error if the collation option is specified and an unacknowledged
- /// write concern is used.
- ///
- /// @exception
- /// Throws mongocxx::write_exception if the operation fails.
- ///
- stdx::optional<bsoncxx::document::value> find_one_and_update(
- bsoncxx::document::view_or_value filter,
- bsoncxx::document::view_or_value update,
- const options::find_one_and_update& options = options::find_one_and_update());
- ///
- /// Finds a single document matching the filter, updates it, and returns either the original
- /// or the newly-updated document.
- ///
- /// @param filter
- /// Document view representing a document that should be updated.
- /// @param update
- /// Pipeline representing the update to apply to a matching document.
- /// @param options
- /// Optional arguments, see options::find_one_and_update.
- ///
- /// @return The original or updated document.
- ///
- /// @exception
- /// Throws mongocxx::logic_error if the collation option is specified and an unacknowledged
- /// write concern is used.
- ///
- /// @exception
- /// Throws mongocxx::write_exception if the operation fails.
- ///
- stdx::optional<bsoncxx::document::value> find_one_and_update(
- bsoncxx::document::view_or_value filter,
- const pipeline& update,
- const options::find_one_and_update& options = options::find_one_and_update());
- ///
- /// Finds a single document matching the filter, updates it, and returns either the original
- /// or the newly-updated document.
- ///
- /// @param filter
- /// Document view representing a document that should be updated.
- /// @param update
- /// Supports the empty update {}.
- /// @param options
- /// Optional arguments, see options::find_one_and_update.
- ///
- /// @return The original or updated document.
- ///
- /// @exception
- /// Throws mongocxx::logic_error if the collation option is specified and an unacknowledged
- /// write concern is used.
- ///
- /// @exception
- /// Throws mongocxx::write_exception if the operation fails.
- ///
- stdx::optional<bsoncxx::document::value> find_one_and_update(
- bsoncxx::document::view_or_value filter,
- std::initializer_list<_empty_doc_tag> update,
- const options::find_one_and_update& options = options::find_one_and_update());
- ///
- /// Finds a single document matching the filter, updates it, and returns either the original
- /// or the newly-updated document.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the operation.
- /// @param filter
- /// Document view representing a document that should be updated.
- /// @param update
- /// Document view representing the update to apply to a matching document.
- /// @param options
- /// Optional arguments, see options::find_one_and_update.
- ///
- /// @return The original or updated document.
- ///
- /// @exception
- /// Throws mongocxx::logic_error if the collation option is specified and an unacknowledged
- /// write concern is used.
- ///
- /// @exception
- /// Throws mongocxx::write_exception if the operation fails.
- ///
- stdx::optional<bsoncxx::document::value> find_one_and_update(
- const client_session& session,
- bsoncxx::document::view_or_value filter,
- bsoncxx::document::view_or_value update,
- const options::find_one_and_update& options = options::find_one_and_update());
- ///
- /// Finds a single document matching the filter, updates it, and returns either the original
- /// or the newly-updated document.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the operation.
- /// @param filter
- /// Document view representing a document that should be updated.
- /// @param update
- /// Pipeline representing the update to apply to a matching document.
- /// @param options
- /// Optional arguments, see options::find_one_and_update.
- ///
- /// @return The original or updated document.
- ///
- /// @exception
- /// Throws mongocxx::logic_error if the collation option is specified and an unacknowledged
- /// write concern is used.
- ///
- /// @exception
- /// Throws mongocxx::write_exception if the operation fails.
- ///
- stdx::optional<bsoncxx::document::value> find_one_and_update(
- const client_session& session,
- bsoncxx::document::view_or_value filter,
- const pipeline& update,
- const options::find_one_and_update& options = options::find_one_and_update());
- ///
- /// Finds a single document matching the filter, updates it, and returns either the original
- /// or the newly-updated document.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the operation.
- /// @param filter
- /// Document view representing a document that should be updated.
- /// @param update
- /// Supports the empty update {}.
- /// @param options
- /// Optional arguments, see options::find_one_and_update.
- ///
- /// @return The original or updated document.
- ///
- /// @exception
- /// Throws mongocxx::logic_error if the collation option is specified and an unacknowledged
- /// write concern is used.
- ///
- /// @exception
- /// Throws mongocxx::write_exception if the operation fails.
- ///
- stdx::optional<bsoncxx::document::value> find_one_and_update(
- const client_session& session,
- bsoncxx::document::view_or_value filter,
- std::initializer_list<_empty_doc_tag> update,
- const options::find_one_and_update& options = options::find_one_and_update());
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Inserts a single document into the collection. If the document is missing an identifier
- /// (@c _id field) one will be generated for it.
- ///
- /// @param document
- /// The document to insert.
- /// @param options
- /// Optional arguments, see options::insert.
- ///
- /// @return The optional result of attempting to perform the insert.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws mongocxx::bulk_write_exception if the operation fails.
- stdx::optional<result::insert_one> insert_one(bsoncxx::document::view_or_value document,
- const options::insert& options = {});
- ///
- /// Inserts a single document into the collection. If the document is missing an identifier
- /// (@c _id field) one will be generated for it.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the insert.
- /// @param document
- /// The document to insert.
- /// @param options
- /// Optional arguments, see options::insert.
- ///
- /// @return The optional result of attempting to perform the insert.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws mongocxx::bulk_write_exception if the operation fails.
- stdx::optional<result::insert_one> insert_one(const client_session& session,
- bsoncxx::document::view_or_value document,
- const options::insert& options = {});
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Inserts multiple documents into the collection. 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.
- ///
- /// @tparam container_type
- /// The container type. Must meet the requirements for the container concept with a value
- /// type of model::write.
- ///
- /// @param container
- /// Container of a documents to insert.
- /// @param options
- /// Optional arguments, see options::insert.
- ///
- /// @return The optional result of attempting to performing the insert.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws mongocxx::bulk_write_exception when the operation fails.
- ///
- template <typename container_type>
- MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
- const container_type& container, const options::insert& options = options::insert());
- ///
- /// Inserts multiple documents into the collection. If any of the documents are missing
- /// identifiers the driver will generate them.
- ///
- /// @tparam container_type
- /// The container type. Must meet the requirements for the container concept with a value
- /// type of model::write.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the inserts.
- /// @param container
- /// Container of a documents to insert.
- /// @param options
- /// Optional arguments, see options::insert.
- ///
- /// @return The optional result of attempting to performing the insert.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws mongocxx::bulk_write_exception when the operation fails.
- ///
- template <typename container_type>
- MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
- const client_session& session,
- const container_type& container,
- const options::insert& options = options::insert());
- ///
- /// @{
- ///
- /// Inserts multiple documents into the collection. 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.
- ///
- /// @tparam document_view_iterator_type
- /// The iterator type. Must meet the requirements for the input iterator concept with a value
- /// type of bsoncxx::document::view.
- ///
- /// @param begin
- /// Iterator pointing to the first document to be inserted.
- /// @param end
- /// Iterator pointing to the end of the documents to be inserted.
- /// @param options
- /// Optional arguments, see options::insert.
- ///
- /// @return The result of attempting to performing the insert.
- ///
- /// @throws mongocxx::bulk_write_exception if the operation fails.
- ///
- template <typename document_view_iterator_type>
- MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
- document_view_iterator_type begin,
- document_view_iterator_type end,
- const options::insert& options = options::insert());
- ///
- /// Inserts multiple documents into the collection. If any of the documents are missing
- /// identifiers the driver will generate them.
- ///
- /// @tparam document_view_iterator_type
- /// The iterator type. Must meet the requirements for the input iterator concept with a value
- /// type of bsoncxx::document::view.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the inserts.
- /// @param begin
- /// Iterator pointing to the first document to be inserted.
- /// @param end
- /// Iterator pointing to the end of the documents to be inserted.
- /// @param options
- /// Optional arguments, see options::insert.
- ///
- /// @return The result of attempting to performing the insert.
- ///
- /// @throws mongocxx::bulk_write_exception if the operation fails.
- ///
- template <typename document_view_iterator_type>
- MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
- const client_session& session,
- document_view_iterator_type begin,
- document_view_iterator_type end,
- const options::insert& options = options::insert());
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Returns a list of the indexes currently on this collection.
- ///
- /// @return Cursor yielding the index specifications.
- ///
- /// @throws mongocxx::operation_exception if the operation fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/listIndexes/
- ///
- cursor list_indexes() const;
- ///
- /// Returns a list of the indexes currently on this collection.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the operation.
- ///
- /// @return Cursor yielding the index specifications.
- ///
- /// @throws mongocxx::operation_exception if the operation fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/listIndexes/
- ///
- cursor list_indexes(const client_session& session) const;
- ///
- /// @}
- ///
- ///
- /// Returns the name of this collection.
- ///
- /// @return The name of the collection. The return value of this method is invalidated by any
- /// subsequent call to collection::rename() on this collection object.
- ///
- stdx::string_view name() const;
- ///
- /// Rename this collection.
- ///
- /// @param new_name The new name to assign to the collection.
- /// @param drop_target_before_rename Whether to overwrite any
- /// existing collections called new_name. The default is false.
- /// @param write_concern (optional)
- /// The write concern to use for this operation. Defaults to the collection wide write
- /// concern if none is provided.
- ///
- /// @exception
- /// mongocxx::operation_exception if the operation fails.
- ///
- /// @see
- /// https://docs.mongodb.com/master/reference/command/renameCollection/
- ///
- /// @note
- /// Write concern supported only for MongoDB 3.4+.
- ///
- void rename(bsoncxx::string::view_or_value new_name,
- bool drop_target_before_rename = false,
- const bsoncxx::stdx::optional<write_concern>& write_concern = {});
- ///
- /// Rename this collection.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the rename.
- /// @param new_name The new name to assign to the collection.
- /// @param drop_target_before_rename Whether to overwrite any
- /// existing collections called new_name. The default is false.
- /// @param write_concern (optional)
- /// The write concern to use for this operation. Defaults to the collection wide write
- /// concern if none is provided.
- ///
- /// @exception
- /// mongocxx::operation_exception if the operation fails.
- ///
- /// @see
- /// https://docs.mongodb.com/master/reference/command/renameCollection/
- ///
- /// @note
- /// Write concern supported only for MongoDB 3.4+.
- ///
- void rename(const client_session& session,
- bsoncxx::string::view_or_value new_name,
- bool drop_target_before_rename = false,
- const bsoncxx::stdx::optional<write_concern>& write_concern = {});
- ///
- /// @}
- ///
- ///
- /// Sets the read_concern for this collection. Changes will not have any effect on existing
- /// cursors or other read operations which use the previously-set read concern.
- ///
- /// @param rc
- /// The new @c read_concern
- ///
- /// @see https://docs.mongodb.com/master/reference/read-concern/
- ///
- void read_concern(class read_concern rc);
- ///
- /// Gets the read_concern for the collection.
- ///
- /// If a read_concern has not been explicitly set for this collection object, it inherits
- /// the read_concern from its parent database or client object.
- ///
- /// @return The current read_concern.
- ///
- class read_concern read_concern() const;
- ///
- /// Sets the read_preference for this collection. Changes will not have any effect on existing
- /// cursors or other read operations which use the read preference.
- ///
- /// @param rp
- /// The read_preference to set.
- ///
- /// @see https://docs.mongodb.com/master/core/read-preference/
- ///
- void read_preference(class read_preference rp);
- ///
- /// Gets the read_preference for the collection.
- ///
- /// @return The current read_preference.
- ///
- /// @see https://docs.mongodb.com/master/core/read-preference/
- ///
- class read_preference read_preference() const;
- ///
- /// @{
- ///
- /// Replaces a single document matching the provided filter in this collection.
- ///
- /// @param filter
- /// Document representing the match criteria.
- /// @param replacement
- /// The replacement document.
- /// @param options
- /// Optional arguments, see options::replace.
- ///
- /// @return The optional result of attempting to replace a document.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws
- /// mongocxx::logic_error if the replacement is invalid, or mongocxx::bulk_write_exception if
- /// the operation fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/update/
- ///
- stdx::optional<result::replace_one> replace_one(
- bsoncxx::document::view_or_value filter,
- bsoncxx::document::view_or_value replacement,
- const options::replace& options = options::replace{});
- ///
- /// Replaces a single document matching the provided filter in this collection.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the replace.
- /// @param filter
- /// Document representing the match criteria.
- /// @param replacement
- /// The replacement document.
- /// @param options
- /// Optional arguments, see options::replace.
- ///
- /// @return The optional result of attempting to replace a document.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws
- /// mongocxx::logic_error if the replacement is invalid, or mongocxx::bulk_write_exception if
- /// the operation fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/update/
- ///
- stdx::optional<result::replace_one> replace_one(
- const client_session& session,
- bsoncxx::document::view_or_value filter,
- bsoncxx::document::view_or_value replacement,
- const options::replace& options = options::replace{});
- ///
- /// @{
- ///
- /// Updates multiple documents matching the provided filter in this collection.
- ///
- /// @param filter
- /// Document representing the match criteria.
- /// @param update
- /// Document representing the update to be applied to matching documents.
- /// @param options
- /// Optional arguments, see options::update.
- ///
- /// @return The optional result of attempting to update multiple documents.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws
- /// mongocxx::logic_error if the update is invalid, or mongocxx::bulk_write_exception if the
- /// operation fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/update/
- ///
- stdx::optional<result::update> update_many(bsoncxx::document::view_or_value filter,
- bsoncxx::document::view_or_value update,
- const options::update& options = options::update());
- ///
- /// Updates multiple documents matching the provided filter in this collection.
- ///
- /// @param filter
- /// Document representing the match criteria.
- /// @param update
- /// Pipeline representing the update to be applied to matching documents.
- /// @param options
- /// Optional arguments, see options::update.
- ///
- /// @return The optional result of attempting to update multiple documents.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws
- /// mongocxx::logic_error if the update is invalid, or mongocxx::bulk_write_exception if the
- /// operation fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/update/
- ///
- stdx::optional<result::update> update_many(bsoncxx::document::view_or_value filter,
- const pipeline& update,
- const options::update& options = options::update());
- ///
- /// Updates multiple documents matching the provided filter in this collection.
- ///
- /// @param filter
- /// Document representing the match criteria.
- /// @param update
- /// Supports the empty update {}.
- /// @param options
- /// Optional arguments, see options::update.
- ///
- /// @return The optional result of attempting to update multiple documents.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws
- /// mongocxx::logic_error if the update is invalid, or mongocxx::bulk_write_exception if the
- /// operation fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/update/
- ///
- stdx::optional<result::update> update_many(bsoncxx::document::view_or_value filter,
- std::initializer_list<_empty_doc_tag> update,
- const options::update& options = options::update());
- ///
- /// Updates multiple documents matching the provided filter in this collection.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the update.
- /// @param filter
- /// Document representing the match criteria.
- /// @param update
- /// Document representing the update to be applied to matching documents.
- /// @param options
- /// Optional arguments, see options::update.
- ///
- /// @return The optional result of attempting to update multiple documents.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws
- /// mongocxx::logic_error if the update is invalid, or mongocxx::bulk_write_exception if the
- /// operation fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/update/
- ///
- stdx::optional<result::update> update_many(const client_session& session,
- bsoncxx::document::view_or_value filter,
- bsoncxx::document::view_or_value update,
- const options::update& options = options::update());
- ///
- /// Updates multiple documents matching the provided filter in this collection.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the update.
- /// @param filter
- /// Document representing the match criteria.
- /// @param update
- /// Pipeline representing the update to be applied to matching documents.
- /// @param options
- /// Optional arguments, see options::update.
- ///
- /// @return The optional result of attempting to update multiple documents.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws
- /// mongocxx::logic_error if the update is invalid, or mongocxx::bulk_write_exception if the
- /// operation fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/update/
- ///
- stdx::optional<result::update> update_many(const client_session& session,
- bsoncxx::document::view_or_value filter,
- const pipeline& update,
- const options::update& options = options::update());
- ///
- /// Updates multiple documents matching the provided filter in this collection.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the update.
- /// @param filter
- /// Document representing the match criteria.
- /// @param update
- /// Supports the empty update {}.
- /// @param options
- /// Optional arguments, see options::update.
- ///
- /// @return The optional result of attempting to update multiple documents.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws
- /// mongocxx::logic_error if the update is invalid, or mongocxx::bulk_write_exception if the
- /// operation fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/update/
- ///
- stdx::optional<result::update> update_many(const client_session& session,
- bsoncxx::document::view_or_value filter,
- std::initializer_list<_empty_doc_tag> update,
- const options::update& options = options::update());
- ///
- /// @}
- ///
- ///
- /// @{
- ///
- /// Updates a single document matching the provided filter in this collection.
- ///
- /// @param filter
- /// Document representing the match criteria.
- /// @param update
- /// Document representing the update to be applied to a matching document.
- /// @param options
- /// Optional arguments, see options::update.
- ///
- /// @return The optional result of attempting to update a document.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws
- /// mongocxx::logic_error if the update is invalid, or mongocxx::bulk_write_exception if the
- /// operation fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/update/
- ///
- stdx::optional<result::update> update_one(bsoncxx::document::view_or_value filter,
- bsoncxx::document::view_or_value update,
- const options::update& options = options::update());
- ///
- /// Updates a single document matching the provided filter in this collection.
- ///
- /// @param filter
- /// Document representing the match criteria.
- /// @param update
- /// Pipeline representing the update to be applied to a matching document.
- /// @param options
- /// Optional arguments, see options::update.
- ///
- /// @return The optional result of attempting to update a document.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws
- /// mongocxx::logic_error if the update is invalid, or mongocxx::bulk_write_exception if the
- /// operation fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/update/
- ///
- stdx::optional<result::update> update_one(bsoncxx::document::view_or_value filter,
- const pipeline& update,
- const options::update& options = options::update());
- ///
- /// Updates a single document matching the provided filter in this collection.
- ///
- /// @param filter
- /// Document representing the match criteria.
- /// @param update
- /// Supports the empty update {}.
- /// @param options
- /// Optional arguments, see options::update.
- ///
- /// @return The optional result of attempting to update a document.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws
- /// mongocxx::logic_error if the update is invalid, or mongocxx::bulk_write_exception if the
- /// operation fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/update/
- ///
- stdx::optional<result::update> update_one(bsoncxx::document::view_or_value filter,
- std::initializer_list<_empty_doc_tag> update,
- const options::update& options = options::update());
- ///
- /// Updates a single document matching the provided filter in this collection.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the update.
- /// @param filter
- /// Document representing the match criteria.
- /// @param update
- /// Document representing the update to be applied to a matching document.
- /// @param options
- /// Optional arguments, see options::update.
- ///
- /// @return The optional result of attempting to update a document.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws
- /// mongocxx::logic_error if the update is invalid, or mongocxx::bulk_write_exception if the
- /// operation fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/update/
- ///
- stdx::optional<result::update> update_one(const client_session& session,
- bsoncxx::document::view_or_value filter,
- bsoncxx::document::view_or_value update,
- const options::update& options = options::update());
- ///
- /// Updates a single document matching the provided filter in this collection.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the update.
- /// @param filter
- /// Document representing the match criteria.
- /// @param update
- /// Pipeline representing the update to be applied to a matching document.
- /// @param options
- /// Optional arguments, see options::update.
- ///
- /// @return The optional result of attempting to update a document.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws
- /// mongocxx::logic_error if the update is invalid, or mongocxx::bulk_write_exception if the
- /// operation fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/update/
- ///
- stdx::optional<result::update> update_one(const client_session& session,
- bsoncxx::document::view_or_value filter,
- const pipeline& update,
- const options::update& options = options::update());
- ///
- /// Updates a single document matching the provided filter in this collection.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the update.
- /// @param filter
- /// Document representing the match criteria.
- /// @param update
- /// Supports the empty update {}.
- /// @param options
- /// Optional arguments, see options::update.
- ///
- /// @return The optional result of attempting to update a document.
- /// If the write concern is unacknowledged, the optional will be
- /// disengaged.
- ///
- /// @throws
- /// mongocxx::logic_error if the update is invalid, or mongocxx::bulk_write_exception if the
- /// operation fails.
- ///
- /// @see https://docs.mongodb.com/master/reference/command/update/
- ///
- stdx::optional<result::update> update_one(const client_session& session,
- bsoncxx::document::view_or_value filter,
- std::initializer_list<_empty_doc_tag> update,
- const options::update& options = options::update());
- ///
- /// @}
- ///
- ///
- /// Sets the write_concern for this collection. Changes will not have any effect on existing
- /// write operations.
- ///
- /// @param wc
- /// The new write_concern to use.
- ///
- void write_concern(class write_concern wc);
- ///
- /// Gets the write_concern for the collection.
- ///
- /// @return The current write_concern.
- ///
- class write_concern write_concern() const;
- ///
- /// Gets an index_view to the collection.
- index_view indexes();
- ///
- /// @{
- ///
- /// Gets a change stream on this collection with an empty pipeline.
- /// Change streams are only supported with a "majority" read concern or no read concern.
- ///
- /// @param options
- /// The options to use when creating the change stream.
- ///
- /// @return
- /// A change stream on this collection.
- ///
- /// @see https://docs.mongodb.com/manual/changeStreams/
- ///
- change_stream watch(const options::change_stream& options = {});
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the watch operation.
- /// @param options
- /// The options to use when creating the change stream.
- ///
- /// @return
- /// A change stream on this collection.
- ///
- /// @see https://docs.mongodb.com/manual/changeStreams/
- ///
- change_stream watch(const client_session& session, const options::change_stream& options = {});
- ///
- /// Gets a change stream on this collection.
- /// Change streams are only supported with a "majority" read concern or no read concern.
- ///
- /// @param pipe
- /// The aggregation pipeline to be used on the change notifications.
- /// Only a subset of pipeline operations are supported for change streams. For more
- /// information see the change streams documentation.
- /// @param options
- /// The options to use when creating the change stream.
- ///
- /// @return
- /// A change stream on this collection.
- ///
- /// @see https://docs.mongodb.com/manual/changeStreams/
- ///
- change_stream watch(const pipeline& pipe, const options::change_stream& options = {});
- ///
- /// Gets a change stream on this collection.
- ///
- /// @param session
- /// The mongocxx::client_session with which to perform the watch operation.
- /// @param pipe
- /// The aggregation pipeline to be used on the change notifications.
- /// @param options
- /// The options to use when creating the change stream.
- ///
- /// @return
- /// A change stream on this collection.
- ///
- /// @see https://docs.mongodb.com/manual/changeStreams/
- ///
- change_stream watch(const client_session& session,
- const pipeline& pipe,
- const options::change_stream& options = {});
- ///
- /// @}
- ///
- private:
- friend class bulk_write;
- friend class database;
- MONGOCXX_PRIVATE collection(const database& database,
- bsoncxx::string::view_or_value collection_name);
- MONGOCXX_PRIVATE collection(const database& database, void* collection);
- MONGOCXX_PRIVATE cursor _aggregate(const client_session* session,
- const pipeline& pipeline,
- const options::aggregate& options);
- MONGOCXX_PRIVATE std::int64_t _count(const client_session* session,
- bsoncxx::document::view_or_value filter,
- const options::count& options);
- MONGOCXX_PRIVATE std::int64_t _count_documents(const client_session* session,
- bsoncxx::document::view_or_value filter,
- const options::count& options);
- MONGOCXX_PRIVATE bsoncxx::document::value _create_index(
- const client_session* session,
- bsoncxx::document::view_or_value keys,
- bsoncxx::document::view_or_value index_options,
- options::index_view operation_options);
- MONGOCXX_PRIVATE stdx::optional<result::delete_result> _delete_many(
- const client_session* session,
- bsoncxx::document::view_or_value filter,
- const options::delete_options& options);
- MONGOCXX_PRIVATE stdx::optional<result::delete_result> _delete_one(
- const client_session* session,
- bsoncxx::document::view_or_value filter,
- const options::delete_options& options);
- MONGOCXX_PRIVATE cursor _distinct(const client_session* session,
- bsoncxx::string::view_or_value name,
- bsoncxx::document::view_or_value filter,
- const options::distinct& options);
- MONGOCXX_PRIVATE void _drop(
- const client_session* session,
- const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern);
- MONGOCXX_PRIVATE cursor _find(const client_session* session,
- bsoncxx::document::view_or_value filter,
- const options::find& options);
- MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one(
- const client_session* session,
- bsoncxx::document::view_or_value filter,
- const options::find& options);
- MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_delete(
- const client_session* session,
- bsoncxx::document::view_or_value filter,
- const options::find_one_and_delete& options);
- MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_replace(
- const client_session* session,
- bsoncxx::document::view_or_value filter,
- bsoncxx::document::view_or_value replacement,
- const options::find_one_and_replace& options);
- MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_update(
- const client_session* session,
- bsoncxx::document::view_or_value filter,
- bsoncxx::document::view_or_value update,
- const options::find_one_and_update& options);
- MONGOCXX_PRIVATE stdx::optional<result::insert_one> _insert_one(
- const client_session* session,
- bsoncxx::document::view_or_value document,
- const options::insert& options);
- MONGOCXX_PRIVATE void _rename(
- const client_session* session,
- bsoncxx::string::view_or_value new_name,
- bool drop_target_before_rename,
- const bsoncxx::stdx::optional<class write_concern>& write_concern);
- MONGOCXX_PRIVATE stdx::optional<result::replace_one> _replace_one(
- const client_session* session,
- const options::bulk_write& bulk_opts,
- const model::replace_one& replace_op);
- MONGOCXX_PRIVATE stdx::optional<result::replace_one> _replace_one(
- const client_session* session,
- bsoncxx::document::view_or_value filter,
- bsoncxx::document::view_or_value replacement,
- const options::replace& options);
- MONGOCXX_PRIVATE stdx::optional<result::update> _update_one(
- const client_session* session,
- bsoncxx::document::view_or_value filter,
- bsoncxx::document::view_or_value update,
- const options::update& options);
- MONGOCXX_PRIVATE stdx::optional<result::update> _update_many(
- const client_session* session,
- bsoncxx::document::view_or_value filter,
- bsoncxx::document::view_or_value update,
- const options::update& options);
- MONGOCXX_PRIVATE change_stream _watch(const client_session* session,
- const pipeline& pipe,
- const options::change_stream& options);
- // Helpers for the insert_many method templates.
- class bulk_write _init_insert_many(const options::insert& options,
- const client_session* session);
- void _insert_many_doc_handler(class bulk_write& writes,
- bsoncxx::builder::basic::array& inserted_ids,
- bsoncxx::document::view doc) const;
- stdx::optional<result::insert_many> _exec_insert_many(
- class bulk_write& writes, bsoncxx::builder::basic::array& inserted_ids);
- template <typename document_view_iterator_type>
- MONGOCXX_PRIVATE stdx::optional<result::insert_many> _insert_many(
- const client_session* session,
- document_view_iterator_type begin,
- document_view_iterator_type end,
- const options::insert& options);
- class MONGOCXX_PRIVATE impl;
- MONGOCXX_PRIVATE impl& _get_impl();
- MONGOCXX_PRIVATE const impl& _get_impl() const;
- std::unique_ptr<impl> _impl;
- };
- MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::write(
- const model::write& write, const options::bulk_write& options) {
- return create_bulk_write(options).append(write).execute();
- }
- MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::write(
- const client_session& session, const model::write& write, const options::bulk_write& options) {
- return create_bulk_write(session, options).append(write).execute();
- }
- template <typename container_type>
- MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
- const container_type& requests, const options::bulk_write& options) {
- return bulk_write(requests.begin(), requests.end(), options);
- }
- template <typename container_type>
- MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
- const client_session& session,
- const container_type& requests,
- const options::bulk_write& options) {
- return bulk_write(session, requests.begin(), requests.end(), options);
- }
- template <typename write_model_iterator_type>
- MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
- write_model_iterator_type begin,
- write_model_iterator_type end,
- const options::bulk_write& options) {
- auto writes = create_bulk_write(options);
- std::for_each(begin, end, [&](const model::write& current) { writes.append(current); });
- return writes.execute();
- }
- template <typename write_model_iterator_type>
- MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
- const client_session& session,
- write_model_iterator_type begin,
- write_model_iterator_type end,
- const options::bulk_write& options) {
- auto writes = create_bulk_write(session, options);
- std::for_each(begin, end, [&](const model::write& current) { writes.append(current); });
- return writes.execute();
- }
- template <typename container_type>
- MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
- const container_type& container, const options::insert& options) {
- return insert_many(container.begin(), container.end(), options);
- }
- template <typename container_type>
- MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
- const client_session& session,
- const container_type& container,
- const options::insert& options) {
- return insert_many(session, container.begin(), container.end(), options);
- }
- template <typename document_view_iterator_type>
- MONGOCXX_INLINE stdx::optional<result::insert_many> collection::_insert_many(
- const client_session* session,
- document_view_iterator_type begin,
- document_view_iterator_type end,
- const options::insert& options) {
- bsoncxx::builder::basic::array inserted_ids;
- auto writes = _init_insert_many(options, session);
- std::for_each(begin, end, [&inserted_ids, &writes, this](bsoncxx::document::view doc) {
- _insert_many_doc_handler(writes, inserted_ids, doc);
- });
- return _exec_insert_many(writes, inserted_ids);
- }
- template <typename document_view_iterator_type>
- MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
- document_view_iterator_type begin,
- document_view_iterator_type end,
- const options::insert& options) {
- return _insert_many(nullptr, begin, end, options);
- }
- template <typename document_view_iterator_type>
- MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
- const client_session& session,
- document_view_iterator_type begin,
- document_view_iterator_type end,
- const options::insert& options) {
- return _insert_many(&session, begin, end, options);
- }
- MONGOCXX_INLINE_NAMESPACE_END
- } // namespace mongocxx
- #include <mongocxx/config/postlude.hpp>
|