|
15 | 15 | */
|
16 | 16 | package com.mongodb.kotlin.client.coroutine
|
17 | 17 |
|
| 18 | +import com.mongodb.ClientBulkWriteException |
18 | 19 | import com.mongodb.ClientSessionOptions
|
| 20 | +import com.mongodb.MongoClientSettings |
| 21 | +import com.mongodb.MongoException |
19 | 22 | import com.mongodb.ReadConcern
|
20 | 23 | import com.mongodb.ReadPreference
|
21 | 24 | import com.mongodb.WriteConcern
|
22 | 25 | import com.mongodb.annotations.Alpha
|
23 | 26 | import com.mongodb.annotations.Reason
|
| 27 | +import com.mongodb.client.model.bulk.ClientBulkWriteOptions |
| 28 | +import com.mongodb.client.model.bulk.ClientBulkWriteResult |
| 29 | +import com.mongodb.client.model.bulk.ClientNamespacedDeleteManyModel |
| 30 | +import com.mongodb.client.model.bulk.ClientNamespacedUpdateManyModel |
| 31 | +import com.mongodb.client.model.bulk.ClientNamespacedWriteModel |
24 | 32 | import com.mongodb.reactivestreams.client.MongoCluster as JMongoCluster
|
25 | 33 | import java.util.concurrent.TimeUnit
|
26 | 34 | import kotlinx.coroutines.flow.Flow
|
@@ -307,4 +315,111 @@ public open class MongoCluster protected constructor(private val wrapped: JMongo
|
307 | 315 | clientSession: ClientSession,
|
308 | 316 | pipeline: List<Bson> = emptyList()
|
309 | 317 | ): ChangeStreamFlow<T> = watch(clientSession, pipeline, T::class.java)
|
| 318 | + |
| 319 | + /** |
| 320 | + * Executes a client-level bulk write operation. This method is functionally equivalent to |
| 321 | + * [bulkWrite(models, options)][bulkWrite] with the |
| 322 | + * [default options][ClientBulkWriteOptions.clientBulkWriteOptions]. |
| 323 | + * |
| 324 | + * This operation supports [retryable writes][MongoClientSettings.getRetryWrites]. Depending on the number of |
| 325 | + * `models`, encoded size of `models`, and the size limits in effect, executing this operation may require multiple |
| 326 | + * `bulkWrite` commands. The eligibility for retries is determined per each `bulkWrite` command: |
| 327 | + * [ClientNamespacedUpdateManyModel], [ClientNamespacedDeleteManyModel] in a command render it non-retryable. |
| 328 | + * |
| 329 | + * This operation is not supported by MongoDB Atlas Serverless instances. |
| 330 | + * |
| 331 | + * @param models The [individual write operations][ClientNamespacedWriteModel]. |
| 332 | + * @return The [ClientBulkWriteResult] if the operation is successful. |
| 333 | + * @throws ClientBulkWriteException If and only if the operation is unsuccessful or partially unsuccessful, and |
| 334 | + * there is at least one of the following pieces of information to report: |
| 335 | + * [ClientBulkWriteException.getWriteConcernErrors], [ClientBulkWriteException.getWriteErrors], |
| 336 | + * [ClientBulkWriteException.getPartialResult]. |
| 337 | + * @throws MongoException Only if the operation is unsuccessful. |
| 338 | + * @see [BulkWrite command](https://www.mongodb.com/docs/manual/reference/command/bulkWrite/) |
| 339 | + * @since 5.3 |
| 340 | + */ |
| 341 | + public suspend fun bulkWrite(models: List<ClientNamespacedWriteModel>): ClientBulkWriteResult = |
| 342 | + wrapped.bulkWrite(models).awaitSingle() |
| 343 | + |
| 344 | + /** |
| 345 | + * Executes a client-level bulk write operation. |
| 346 | + * |
| 347 | + * This operation supports [retryable writes][MongoClientSettings.getRetryWrites]. Depending on the number of |
| 348 | + * `models`, encoded size of `models`, and the size limits in effect, executing this operation may require multiple |
| 349 | + * `bulkWrite` commands. The eligibility for retries is determined per each `bulkWrite` command: |
| 350 | + * [ClientNamespacedUpdateManyModel], [ClientNamespacedDeleteManyModel] in a command render it non-retryable. |
| 351 | + * |
| 352 | + * This operation is not supported by MongoDB Atlas Serverless instances. |
| 353 | + * |
| 354 | + * @param models The [individual write operations][ClientNamespacedWriteModel]. |
| 355 | + * @param options The [options][ClientBulkWriteOptions]. |
| 356 | + * @return The [ClientBulkWriteResult] if the operation is successful. |
| 357 | + * @throws ClientBulkWriteException If and only if the operation is unsuccessful or partially unsuccessful, and |
| 358 | + * there is at least one of the following pieces of information to report: |
| 359 | + * [ClientBulkWriteException.getWriteConcernErrors], [ClientBulkWriteException.getWriteErrors], |
| 360 | + * [ClientBulkWriteException.getPartialResult]. |
| 361 | + * @throws MongoException Only if the operation is unsuccessful. |
| 362 | + * @see [BulkWrite command](https://www.mongodb.com/docs/manual/reference/command/bulkWrite/) |
| 363 | + * @since 5.3 |
| 364 | + */ |
| 365 | + public suspend fun bulkWrite( |
| 366 | + models: List<ClientNamespacedWriteModel>, |
| 367 | + options: ClientBulkWriteOptions |
| 368 | + ): ClientBulkWriteResult = wrapped.bulkWrite(models, options).awaitSingle() |
| 369 | + |
| 370 | + /** |
| 371 | + * Executes a client-level bulk write operation. This method is functionally equivalent to |
| 372 | + * [bulkWrite(clientSession, models, options)][bulkWrite] with the |
| 373 | + * [default options][ClientBulkWriteOptions.clientBulkWriteOptions]. |
| 374 | + * |
| 375 | + * This operation supports [retryable writes][MongoClientSettings.getRetryWrites]. Depending on the number of |
| 376 | + * `models`, encoded size of `models`, and the size limits in effect, executing this operation may require multiple |
| 377 | + * `bulkWrite` commands. The eligibility for retries is determined per each `bulkWrite` command: |
| 378 | + * [ClientNamespacedUpdateManyModel], [ClientNamespacedDeleteManyModel] in a command render it non-retryable. |
| 379 | + * |
| 380 | + * This operation is not supported by MongoDB Atlas Serverless instances. |
| 381 | + * |
| 382 | + * @param clientSession The [client session][ClientSession] with which to associate this operation. |
| 383 | + * @param models The [individual write operations][ClientNamespacedWriteModel]. |
| 384 | + * @return The [ClientBulkWriteResult] if the operation is successful. |
| 385 | + * @throws ClientBulkWriteException If and only if the operation is unsuccessful or partially unsuccessful, and |
| 386 | + * there is at least one of the following pieces of information to report: |
| 387 | + * [ClientBulkWriteException.getWriteConcernErrors], [ClientBulkWriteException.getWriteErrors], |
| 388 | + * [ClientBulkWriteException.getPartialResult]. |
| 389 | + * @throws MongoException Only if the operation is unsuccessful. |
| 390 | + * @see [BulkWrite command](https://www.mongodb.com/docs/manual/reference/command/bulkWrite/) |
| 391 | + * @since 5.3 |
| 392 | + */ |
| 393 | + public suspend fun bulkWrite( |
| 394 | + clientSession: ClientSession, |
| 395 | + models: List<ClientNamespacedWriteModel> |
| 396 | + ): ClientBulkWriteResult = wrapped.bulkWrite(clientSession.wrapped, models).awaitSingle() |
| 397 | + |
| 398 | + /** |
| 399 | + * Executes a client-level bulk write operation. |
| 400 | + * |
| 401 | + * This operation supports [retryable writes][MongoClientSettings.getRetryWrites]. Depending on the number of |
| 402 | + * `models`, encoded size of `models`, and the size limits in effect, executing this operation may require multiple |
| 403 | + * `bulkWrite` commands. The eligibility for retries is determined per each `bulkWrite` command: |
| 404 | + * [ClientNamespacedUpdateManyModel], [ClientNamespacedDeleteManyModel] in a command render it non-retryable. |
| 405 | + * |
| 406 | + * This operation is not supported by MongoDB Atlas Serverless instances. |
| 407 | + * |
| 408 | + * @param clientSession The [client session][ClientSession] with which to associate this operation. |
| 409 | + * @param models The [individual write operations][ClientNamespacedWriteModel]. |
| 410 | + * @param options The [options][ClientBulkWriteOptions]. |
| 411 | + * @return The [ClientBulkWriteResult] if the operation is successful. |
| 412 | + * @throws ClientBulkWriteException If and only if the operation is unsuccessful or partially unsuccessful, and |
| 413 | + * there is at least one of the following pieces of information to report: |
| 414 | + * [ClientBulkWriteException.getWriteConcernErrors], [ClientBulkWriteException.getWriteErrors], |
| 415 | + * [ClientBulkWriteException.getPartialResult]. |
| 416 | + * @throws MongoException Only if the operation is unsuccessful. |
| 417 | + * @see [BulkWrite command](https://www.mongodb.com/docs/manual/reference/command/bulkWrite/) |
| 418 | + * @since 5.3 |
| 419 | + */ |
| 420 | + public suspend fun bulkWrite( |
| 421 | + clientSession: ClientSession, |
| 422 | + models: List<ClientNamespacedWriteModel>, |
| 423 | + options: ClientBulkWriteOptions |
| 424 | + ): ClientBulkWriteResult = wrapped.bulkWrite(clientSession.wrapped, models, options).awaitSingle() |
310 | 425 | }
|
0 commit comments