[CXX-2147] mongocxx::v_noabi::bulk_write_exception Created: 05/Jan/21  Updated: 27/Oct/23  Resolved: 16/Feb/21

Status: Closed
Project: C++ Driver
Component/s: Build
Affects Version/s: 3.6.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Code Bau Assignee: Kevin Albertson
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10 x64, Visual Studio 2019


Backwards Compatibility: Fully Compatible

 Description   

Hi, 
here is my full story: https://stackoverflow.com/questions/65534784/i-get-an-error-running-the-base-c-code-for-mongodb-with-windows-10-visual-stu
At this point, we use: HP OMEN 17 i7-9750H/32GB/512 RTX2060 240Hz with Windows 10 x64. Working on Visual Studio 2019.  

I set up the latest drivers for C ++ (mongo-c-driver-1.17.3, mongo-cxx-driver-r3.6.2) After following these steps: http://mongoc.org/libmongoc/current/installing.html
http://mongocxx.org/mongocxx-v3/installation/windows/
How to set up Visual Studio project settings with mongo-cxx-driver?
I wrote the code according to this instruction:
http://mongocxx.org/mongocxx-v3/tutorial/

#include <cstdint>
#include <iostream>
#include <vector>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/stdx.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/instance.hpp>
#include <bsoncxx/builder/stream/helpers.hpp>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/builder/stream/array.hpp>
 
using bsoncxx::builder::stream::close_array;
using bsoncxx::builder::stream::close_document;
using bsoncxx::builder::stream::document;
using bsoncxx::builder::stream::finalize;
using bsoncxx::builder::stream::open_array;
using bsoncxx::builder::stream::open_document;
int main(int, char**) {
 mongocxx::instance inst{};
 mongocxx::client conn{ mongocxx::uri{"mongodb+srv://<username>:<password>@wipcluster.qetq2.mongodb.net/userdata?retryWrites=true&w=majority"} };
 mongocxx::database db = conn["userdata"];
 mongocxx::collection coll = db["test"];
 auto builder = bsoncxx::builder::stream::document{};
 bsoncxx::document::value doc_value = builder
 << "name" << "MongoDB"
 << "type" << "database"
 << "count" << 1
 << "versions" << bsoncxx::builder::stream::open_array
 << "v3.2" << "v3.0" << "v2.6"
 << close_array
 << "info" << bsoncxx::builder::stream::open_document
 << "x" << 203
 << "y" << 102
 << bsoncxx::builder::stream::close_document
 << bsoncxx::builder::stream::finalize;
bsoncxx::document::view view = doc_value.view();
bsoncxx::stdx::optional<mongocxx::result::insert_one> result =
 coll.insert_one(view);
}

Finally i get:

Exception thrown at 0x00007FFC99A73B29 in Project3.exe: Microsoft C++ exception: mongocxx::v_noabi::bulk_write_exception at memory location 0x0000001D6D6FE0C0. 

Unhandled exception at 0x00007FFC99A73B29 in Project3.exe: Microsoft C++ exception: mongocxx::v_noabi::bulk_write_exception at memory location 0x0000001D6D6FE0C0. 


Before that, I used vcpkg with: C - 1.16.1 # 3, C ++ - 3.4.0-5 # 1

#include <iostream> 
#include <bsoncxx/builder/stream/document.hpp> 
#include <bsoncxx/json.hpp> 
#include <mongocxx/client.hpp> 
#include <mongocxx/instance.hpp> 
int main(int, char**) 
{ mongocxx::instance inst{}; 
mongocxx::client conn{mongocxx::uri{"mongodb+srv://<username>:<password>@wipcluster.qetq2.mongodb.net/userdata?retryWrites=true&w=majority"} }; 
bsoncxx::builder::stream::document document{}; 
auto collection = conn["userdata"]["organizations"]; 
document << "hello" << "world1"; 
collection.insert_one(document.view()); 
auto cursor = collection.find({}); 
for (auto&& doc : cursor) 
   { std::cout << bsoncxx::to_json(doc) << std::endl; } 
}

And i get: 

Unhandled exception at 0x761446D2 in nowycalkiem.exe: Microsoft C++ exception: mongocxx::v_noabi::bulk_write_exception at memory location 0x00AFE6AC.

 and,

Unhandled exception at 0x761446D2 in nowycalkiem.exe: Microsoft C++ exception: mongocxx::v_noabi::query_exception at memory location 0x00AFEBB8.

 


This code works fine on old Lenovo G570 15.6 inch Laptop (Core i3-2310M, RAM 4GB, HDD 500GB, DVDRW, Windows 7 with VIsual Studio 2019. 



 Comments   
Comment by Backlog - Core Eng Program Management Team [ 16/Feb/21 ]

There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information.

Comment by Kevin Albertson [ 02/Feb/21 ]

Hi codebaudata@gmail.com. Apologies for the delayed response. I attempted to reproduce using the snippet you included and the mongo-cxx-driver vcpkg. It was able to build, run, and insert without issue.

The contents of the exception may give more information to the source of the error. Can you wrap the insert_one operation with a try/catch to print out the contents of the bulk_write_exception and query_exception?

To do so, add the following includes:

#include <mongocxx/exception/bulk_write_exception.hpp>
#include <mongocxx/exception/query_exception.hpp>

And wrap the insert_one as follows:

 try {
 bsoncxx::stdx::optional<mongocxx::result::insert_one> result =
     coll.insert_one(view);
 } catch (mongocxx::bulk_write_exception& e) {
     std::cout << "code=" << e.code() << std::endl;
     std::cout << "message=" << e.what() << std::endl;
     if (e.raw_server_error()) {
        std::cout << "error reply=" << bsoncxx::to_json (*e.raw_server_error()) << std::endl;
     }
 }

That may help us debug the issue.

Sincerely,
Kevin

Comment by Kevin Albertson [ 05/Jan/21 ]

Hi codebaudata@gmail.com, thank you for the detailed bug report! We will look into this soon.

Generated at Wed Feb 07 22:05:02 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.