@@ -381,36 +381,33 @@ static PHP_METHOD(MongoDB_Driver_BulkWrite, insert)
381381 php_phongo_bulkwrite_t * intern ;
382382 zval * zdocument ;
383383 bson_t bdocument = BSON_INITIALIZER , boptions = BSON_INITIALIZER ;
384- bson_t * bson_out = NULL ;
385- int bson_flags = PHONGO_BSON_ADD_ID ;
386- bson_error_t error = { 0 };
384+ bson_t * bson_out = NULL ;
385+ bson_error_t error = { 0 };
387386
388387 intern = Z_BULKWRITE_OBJ_P (getThis ());
389388
390389 PHONGO_PARSE_PARAMETERS_START (1 , 1 )
391390 Z_PARAM_ARRAY_OR_OBJECT (zdocument )
392391 PHONGO_PARSE_PARAMETERS_END ();
393392
394- bson_flags |= PHONGO_BSON_RETURN_ID ;
395-
396- php_phongo_zval_to_bson (zdocument , bson_flags , & bdocument , & bson_out );
393+ php_phongo_zval_to_bson (zdocument , (PHONGO_BSON_ADD_ID | PHONGO_BSON_RETURN_ID ), & bdocument , & bson_out );
397394
398395 if (EG (exception )) {
399396 goto cleanup ;
400397 }
401398
399+ if (!bson_out ) {
400+ phongo_throw_exception (PHONGO_ERROR_LOGIC , "php_phongo_zval_to_bson() did not return an _id. Please file a bug report." );
401+ goto cleanup ;
402+ }
403+
402404 if (!mongoc_bulk_operation_insert_with_opts (intern -> bulk , & bdocument , & boptions , & error )) {
403405 phongo_throw_exception_from_bson_error_t (& error );
404406 goto cleanup ;
405407 }
406408
407409 intern -> num_ops ++ ;
408410
409- if (!bson_out ) {
410- phongo_throw_exception (PHONGO_ERROR_LOGIC , "Did not receive result from bulk write. Please file a bug report." );
411- goto cleanup ;
412- }
413-
414411 php_phongo_bulkwrite_extract_id (bson_out , & return_value );
415412
416413cleanup :
0 commit comments