-2

I tried the conventional way of passing an array to a wrapper function in which I'm using insertOne to insert data using for loop. No build issues, but while running, I'm hitting this error: Microsoft C++ exception: mongocxx::v_noabi::bulk_write_exception at memory location 0x000000B26C12DF30. Here is my source code.

int main(void) {

char EUI[][20] = { "10205E3710014240", "10205e37100142cc" ,"10205E6910001E58", "10205E371001426C" };
char IP[][15] = { "192.168.85.117" , "192.168.85.114", "192.168.85.186",  "192.168.85.168" };
int i = 4;

push_data(IP, EUI, i);
while (1);
}

void push_data(char IP[][15], char EUI[][20], int count)
{
mongocxx::instance inst{};
mongocxx::client conn{ mongocxx::uri{} };
auto collection = conn["new"]["collection"];

int a;
builder::stream::document builder{};

auto in_array = builder << "subdocs" << builder::stream::open_array;
for (a = 0; a<count; a++) {
        in_array = in_array << builder::stream::open_document << EUI[a] << IP[a]
            << builder::stream::close_document;
}
auto after_array = in_array << builder::stream::close_array;
bsoncxx::document::value doc = after_array << builder::stream::finalize;

bsoncxx::document::view view = doc.view();
for (a = 0; a < count; a++) {
    collection.insert_one(doc.view());
}

auto cursor = collection.find({});

for (auto&& doc : cursor) {
std::cout << bsoncxx::to_json(doc) << std::endl;
}
}
T.Nirupama
  • 11
  • 1
  • When you have a question about code, it's a good idea to include the code in the question, otherwise the question is unanswerable. Similarly if you are expecting someone to write some code for you, you should also include the code you have written in attempting to solve the problem yourself. This gives any answerer more idea of what you are trying to do, what your skill level is etc. I would think this is obvious but apparently not as you're not the first person to post off-topic questions without first finding out what the rules of this site are. – john Jan 29 '19 at 12:06
  • I'll be happy to help answer this if significant additional detail is added – acm Jan 30 '19 at 03:56

1 Answers1

0

Almost certainly, an exception has been thrown from collection.insert_one(doc.view());. You should catch that exception (by using try, and catch), and inspect the contents of the exception, which should tell you more about what is going wrong.

acm
  • 12,183
  • 5
  • 39
  • 68