1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15+ #include < mongocxx/collection.hpp>
16+
1517#include < cstdint>
18+ #include < utility>
19+ #include < tuple>
1620
1721#include < bsoncxx/builder/stream/document.hpp>
1822#include < bsoncxx/builder/stream/helpers.hpp>
23+ #include < bsoncxx/stdx/make_unique.hpp>
24+ #include < bsoncxx/stdx/optional.hpp>
1925#include < bsoncxx/types.hpp>
2026
21- #include < mongocxx/private/client.hpp>
22- #include < mongocxx/private/collection.hpp>
23- #include < mongocxx/private/database.hpp>
24- #include < mongocxx/private/pipeline.hpp>
25- #include < mongocxx/private/bulk_write.hpp>
26- #include < mongocxx/private/read_preference.hpp>
27- #include < mongocxx/private/write_concern.hpp>
28- #include < mongocxx/write_concern.hpp>
29- #include < mongocxx/collection.hpp>
3027#include < mongocxx/client.hpp>
3128#include < mongocxx/exception/bulk_write.hpp>
3229#include < mongocxx/exception/operation.hpp>
30+ #include < mongocxx/exception/query.hpp>
3331#include < mongocxx/exception/write.hpp>
3432#include < mongocxx/model/write.hpp>
33+ #include < mongocxx/private/bulk_write.hpp>
34+ #include < mongocxx/private/client.hpp>
35+ #include < mongocxx/private/collection.hpp>
36+ #include < mongocxx/private/database.hpp>
3537#include < mongocxx/private/libbson.hpp>
3638#include < mongocxx/private/libmongoc.hpp>
39+ #include < mongocxx/private/pipeline.hpp>
40+ #include < mongocxx/private/read_preference.hpp>
41+ #include < mongocxx/private/write_concern.hpp>
3742#include < mongocxx/result/bulk_write.hpp>
3843#include < mongocxx/result/delete.hpp>
3944#include < mongocxx/result/insert_many.hpp>
4045#include < mongocxx/result/insert_one.hpp>
4146#include < mongocxx/result/replace_one.hpp>
4247#include < mongocxx/result/update.hpp>
43-
44- #include < bsoncxx/stdx/optional.hpp>
45- #include < bsoncxx/stdx/make_unique.hpp>
46-
48+ #include < mongocxx/write_concern.hpp>
4749
4850namespace {
4951enum class cursor_flag : uint32_t {
@@ -89,7 +91,7 @@ bsoncxx::stdx::optional<result::bulk_write> collection::bulk_write(
8991 bson_error_t error;
9092
9193 if (!libmongoc::bulk_operation_execute (b, reply.bson (), &error)) {
92- throw exception::bulk_write ();
94+ throw exception::bulk_write (reply. steal (), std::make_tuple (error. message , error. code ) );
9395 }
9496
9597 result::bulk_write result (reply.steal ());
@@ -326,7 +328,7 @@ bsoncxx::stdx::optional<bsoncxx::document::value> collection::find_one_and_repla
326328 rd == options::return_document::k_after, reply.bson (), &error);
327329
328330 if (!r) {
329- throw exception::operation ( );
331+ throw exception::write ( std::move (_impl-> gle ()), std::make_tuple (error. message , error. code ) );
330332 }
331333
332334 bsoncxx::document::view result = reply.view ();
@@ -361,7 +363,7 @@ bsoncxx::stdx::optional<bsoncxx::document::value> collection::find_one_and_updat
361363 rd == options::return_document::k_after, reply.bson (), &error);
362364
363365 if (!r) {
364- throw exception::operation ( );
366+ throw exception::write ( std::move (_impl-> gle ()), std::make_tuple (error. message , error. code ) );
365367 }
366368
367369 bsoncxx::document::view result = reply.view ();
@@ -390,7 +392,7 @@ bsoncxx::stdx::optional<bsoncxx::document::value> collection::find_one_and_delet
390392 true , false , false , reply.bson (), &error);
391393
392394 if (!r) {
393- throw exception::operation ( );
395+ throw exception::write ( std::move (_impl-> gle ()), std::make_tuple (error. message , error. code ) );
394396 }
395397
396398 bsoncxx::document::view result = reply.view ();
@@ -418,7 +420,7 @@ std::int64_t collection::count(bsoncxx::document::view filter, const options::co
418420 options.skip ().value_or (0 ), options.limit ().value_or (0 ), rp_ptr, &error);
419421
420422 if (result < 0 ) {
421- throw exception::operation ( );
423+ throw exception::query ( std::make_tuple (error. message , error. code ) );
422424 }
423425
424426 return result;
@@ -433,7 +435,7 @@ bsoncxx::document::value collection::create_index(bsoncxx::document::view keys,
433435 libmongoc::collection_create_index (_impl->collection_t , bson_keys.bson (), nullptr , &error);
434436
435437 if (!result) {
436- throw exception::operation ();
438+ throw exception::operation (std::make_tuple (error. message , error. code ) );
437439 }
438440
439441 // TODO: return the response from the server, this is not possible now due to the way
@@ -474,7 +476,7 @@ void collection::drop() {
474476 auto result = libmongoc::collection_drop (_impl->collection_t , &error);
475477
476478 if (!result) {
477- throw exception::operation ();
479+ throw exception::operation (std::make_tuple (error. message , error. code ) );
478480 }
479481}
480482
0 commit comments