@@ -796,8 +796,8 @@ _txn_in_progress (mongoc_cmd_parts_t *parts)
796
796
}
797
797
798
798
return (_mongoc_client_session_txn_in_progress (cs )
799
- /* commitTransaction and abortTransaction count as in progress, too. */
800
- || parts -> assembled .is_txn_finish );
799
+ /* commitTransaction and abortTransaction count as in progress, too. */
800
+ || parts -> assembled .is_txn_finish );
801
801
}
802
802
803
803
@@ -827,14 +827,12 @@ mongoc_cmd_parts_assemble (mongoc_cmd_parts_t *parts,
827
827
bson_error_t * error )
828
828
{
829
829
mongoc_server_description_type_t server_type ;
830
- mongoc_server_api_t * api ;
831
830
mongoc_client_session_t * cs ;
832
831
const bson_t * cluster_time = NULL ;
833
832
mongoc_read_prefs_t * prefs = NULL ;
834
833
const char * cmd_name ;
835
834
bool is_get_more ;
836
835
const mongoc_read_prefs_t * prefs_ptr ;
837
- const char * string_version ;
838
836
bool ret = false;
839
837
840
838
ENTRY ;
@@ -994,23 +992,8 @@ mongoc_cmd_parts_assemble (mongoc_cmd_parts_t *parts,
994
992
sending a getmore, or if we are in a transaction. */
995
993
if (parts -> client -> api ) {
996
994
if (!is_get_more && !_txn_in_progress (parts )) {
997
- api = parts -> client -> api ;
998
- string_version = mongoc_server_api_version_to_string (api -> version );
999
-
1000
- bson_append_utf8 (
1001
- & parts -> assembled_body , "apiVersion" , -1 , string_version , -1 );
1002
-
1003
- if (api -> strict .is_set ) {
1004
- bson_append_bool (
1005
- & parts -> assembled_body , "apiStrict" , -1 , api -> strict .value );
1006
- }
1007
-
1008
- if (api -> deprecation_errors .is_set ) {
1009
- bson_append_bool (& parts -> assembled_body ,
1010
- "apiDeprecationErrors" ,
1011
- -1 ,
1012
- api -> deprecation_errors .value );
1013
- }
995
+ _mongoc_cmd_append_server_api (& parts -> assembled_body ,
996
+ parts -> client -> api );
1014
997
}
1015
998
}
1016
999
@@ -1155,3 +1138,43 @@ _mongoc_cmd_append_payload_as_array (const mongoc_cmd_t *cmd, bson_t *out)
1155
1138
1156
1139
bson_append_array_end (out , & bson );
1157
1140
}
1141
+
1142
+ /*--------------------------------------------------------------------------
1143
+ *
1144
+ * _mongoc_cmd_append_server_api --
1145
+ * Append versioned API fields to a mongoc_cmd_t
1146
+ *
1147
+ * Arguments:
1148
+ * cmd The mongoc_cmd_t, which will have versioned API fields added
1149
+ * api A mongoc_server_api_t holding server API information
1150
+ *
1151
+ * Pre-conditions:
1152
+ * - @api is initialized.
1153
+ * - @command_body is initialised
1154
+ *
1155
+ *--------------------------------------------------------------------------
1156
+ */
1157
+ void
1158
+ _mongoc_cmd_append_server_api (bson_t * command_body ,
1159
+ const mongoc_server_api_t * api )
1160
+ {
1161
+ const char * string_version ;
1162
+
1163
+ BSON_ASSERT (command_body );
1164
+ BSON_ASSERT (api );
1165
+
1166
+ string_version = mongoc_server_api_version_to_string (api -> version );
1167
+
1168
+ bson_append_utf8 (command_body , "apiVersion" , -1 , string_version , -1 );
1169
+
1170
+ if (api -> strict .is_set ) {
1171
+ bson_append_bool (command_body , "apiStrict" , -1 , api -> strict .value );
1172
+ }
1173
+
1174
+ if (api -> deprecation_errors .is_set ) {
1175
+ bson_append_bool (command_body ,
1176
+ "apiDeprecationErrors" ,
1177
+ -1 ,
1178
+ api -> deprecation_errors .value );
1179
+ }
1180
+ }
0 commit comments