@@ -4106,6 +4106,27 @@ test_index_with_collation_ok (void)
4106
4106
test_index_with_collation (WIRE_VERSION_COLLATION );
4107
4107
}
4108
4108
4109
+ static void
4110
+ test_insert_duplicate_key (void )
4111
+ {
4112
+ mongoc_client_t * client ;
4113
+ mongoc_collection_t * collection ;
4114
+ bson_error_t error ;
4115
+
4116
+ client = test_framework_client_new ();
4117
+ collection = get_test_collection (client , "test_insert_duplicate_key" );
4118
+ mongoc_collection_insert (collection , MONGOC_INSERT_NONE ,
4119
+ tmp_bson ("{'_id': 1}" ), NULL , NULL );
4120
+
4121
+ ASSERT (!mongoc_collection_insert (collection , MONGOC_INSERT_NONE ,
4122
+ tmp_bson ("{'_id': 1}" ), NULL , & error ));
4123
+ ASSERT_CMPINT (error .domain , = = , MONGOC_ERROR_COMMAND );
4124
+ ASSERT_CMPINT (error .code , = = , MONGOC_ERROR_DUPLICATE_KEY );
4125
+
4126
+ mongoc_collection_destroy (collection );
4127
+ mongoc_client_destroy (client );
4128
+ }
4129
+
4109
4130
void
4110
4131
test_collection_install (TestSuite * suite )
4111
4132
{
@@ -4193,4 +4214,5 @@ test_collection_install (TestSuite *suite)
4193
4214
TestSuite_AddFull (suite , "/Collection/command_fully_qualified" , test_command_fq , NULL , NULL , test_framework_skip_if_mongos );
4194
4215
TestSuite_AddLive (suite , "/Collection/get_index_info" , test_get_index_info );
4195
4216
TestSuite_Add (suite , "/Collection/find_indexes/error" , test_find_indexes_err );
4217
+ TestSuite_AddLive (suite , "/Collection/insert/duplicate_key" , test_insert_duplicate_key );
4196
4218
}
0 commit comments