Summary
Attempting to compare two objects of mongocxx::v_noabi::result::insert_many with non-ObjectID values for "_id" throws an exception.
How to Reproduce
The following test fails:
TEST_CASE("insertMany-equality", "[collection]") { auto client = mongocxx::client(uri{}, test_util::add_test_server_api()); auto coll1 = client["db"]["coll1"]; auto coll2 = client["db"]["coll2"]; // Two results with the same ObjectIDs compares equal: { coll1.drop(); coll2.drop(); std::vector<bsoncxx::document::value> docs; docs.push_back(make_document(kvp("_id", bsoncxx::oid{}))); docs.push_back(make_document(kvp("_id", bsoncxx::oid{}))); auto res1 = coll1.insert_many(docs); auto res2 = coll2.insert_many(docs); REQUIRE(res1 == res2); } // Two results with the same ints fails to compare!: { coll1.drop(); coll2.drop(); std::vector<bsoncxx::document::value> docs; docs.push_back(make_document(kvp("_id", 1))); docs.push_back(make_document(kvp("_id", 2))); auto res1 = coll1.insert_many(docs); auto res2 = coll2.insert_many(docs); REQUIRE(res1 == res2); // exception: expected element type k_oid } }
Additional Background
"_id" can be other BSON types than ObjectID.