Skip to content

Commit 77d075d

Browse files
committed
DOCSP-41130
1 parent 4ddb4d8 commit 77d075d

File tree

3 files changed

+103
-96
lines changed

3 files changed

+103
-96
lines changed

snooty.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ mdb-server = "MongoDB Server"
2929
stable-api = "Stable API"
3030
api = "https://mongodb.github.io/mongo-java-driver/{+version-number+}/apidocs/mongodb-driver-kotlin-sync"
3131
java-api = "https://mongodb.github.io/mongo-java-driver/{+version-number+}"
32-
core-api = "{+java-api+}/apidocs/mongodb-driver-core/"
32+
core-api = "{+java-api+}/apidocs/mongodb-driver-core"
3333
kotlin-docs = "https://kotlinlang.org"

source/connect/stable-api.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ API Documentation
125125
For more information about using the {+stable-api+} with {+driver-short+}, see the
126126
following API documentation:
127127

128-
- `ServerApi <{+core-api+}com/mongodb/ServerApi.html>`__
129-
- `ServerApi.Builder <{+core-api+}com/mongodb/ServerApi.Builder.html>`__
130-
- `ServerApiVersion <{+core-api+}com/mongodb/ServerApiVersion.html>`__
131-
- `ServerAddress <{+core-api+}com/mongodb/ServerAddress.html>`__
132-
- `MongoClientSettings <{+core-api+}com/mongodb/MongoClientSettings.html>`__
133-
- `MongoClientSettings.Builder <{+core-api+}com/mongodb/MongoClientSettings.Builder.html>`__
128+
- `ServerApi <{+core-api+}/com/mongodb/ServerApi.html>`__
129+
- `ServerApi.Builder <{+core-api+}/com/mongodb/ServerApi.Builder.html>`__
130+
- `ServerApiVersion <{+core-api+}/com/mongodb/ServerApiVersion.html>`__
131+
- `ServerAddress <{+core-api+}/com/mongodb/ServerAddress.html>`__
132+
- `MongoClientSettings <{+core-api+}/com/mongodb/MongoClientSettings.html>`__
133+
- `MongoClientSettings.Builder <{+core-api+}/com/mongodb/MongoClientSettings.Builder.html>`__
134134
- `MongoClient <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-client/index.html>`__
135135
- `MongoClient.create() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-client/-factory/create.html>`__

source/write/bulk-write.txt

Lines changed: 96 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The documents in this collection are modeled by the following {+language+} data
5050
Define the Write Operations
5151
---------------------------
5252

53-
For each write operation you want to perform, create a correspinding
53+
For each write operation you want to perform, create a corresponding
5454
instance of one of the following operation classes that inherit from the
5555
generic ``WriteModel`` class:
5656

@@ -65,50 +65,61 @@ Then, pass a list of these instances to the ``bulkWrite()`` method.
6565

6666
The following sections show how to create and use instances of the
6767
preceding classes. The :ref:`kotlin-sync-bulkwrite-method` section
68-
demonstrates how to pass a list of models to the ``bulkWrite()`` method.
68+
demonstrates how to pass a list of models to the ``bulkWrite()`` method
69+
to perform the bulk operation.
6970

7071
Insert Operations
7172
~~~~~~~~~~~~~~~~~
7273

7374
To perform an insert operation, create an ``InsertOneModel`` instance and specify
7475
the document you want to insert.
7576

76-
The following example creates an instance of ``InsertOne``:
77+
The following example creates an instance of ``InsertOneModel``:
7778

7879
.. literalinclude:: /includes/write/bulk.kt
7980
:start-after: start-bulk-insert-one
8081
:end-before: end-bulk-insert-one
8182
:language: kotlin
8283
:copyable:
8384

84-
To insert multiple documents, create an instance of ``InsertOne`` for each document.
85+
To insert multiple documents, create an instance of ``InsertOneModel``
86+
for each document.
87+
88+
.. important::
89+
90+
When performing a bulk operation, the ``InsertOneModel`` cannot
91+
insert a document with an ``_id`` that already exists in the
92+
collection. In this situation, the driver throws a
93+
``MongoBulkWriteException``.
8594

8695
Update Operations
8796
~~~~~~~~~~~~~~~~~
8897

89-
To update a document, create an instance of ``UpdateOne`` and pass in
98+
To update a document, create an instance of ``UpdateOneModel`` and pass
9099
the following arguments:
91100

92101
- A **query filter** that specifies the criteria used to match documents in your collection
93102
- The update operation you want to perform. For more information about update
94103
operations, see the :manual:`Field Update Operators
95104
</reference/operator/update-field/>` guide in the {+mdb-server+} manual.
96105

97-
``UpdateOne`` updates *the first* document that matches your query filter.
106+
An ``UpdateOneModel`` instance specifies an update for *the first*
107+
document that matches your query filter.
98108

99-
The following example creates an instance of ``UpdateOne``:
109+
The following example creates an instance of ``UpdateOneModel``:
100110

101111
.. literalinclude:: /includes/write/bulk.kt
102112
:start-after: start-bulk-update-one
103113
:end-before: end-bulk-update-one
104114
:language: kotlin
105115
:copyable:
106116

107-
To update multiple documents, create an instance of ``UpdateMany`` and pass in
108-
the same arguments. ``UpdateMany`` updates *all* documents that match your query
117+
To update multiple documents, create an instance of ``UpdateManyModel`` and pass
118+
the same arguments as for ``UpdateOneModel``. The ``UpdateManyModel``
119+
class specifies updates for *all* documents that match your query
109120
filter.
110121

111-
The following example creates an instance of ``UpdateMany``:
122+
The following example creates an instance of ``UpdateManyModel``:
112123

113124
.. literalinclude:: /includes/write/bulk.kt
114125
:start-after: start-bulk-update-many
@@ -120,38 +131,42 @@ Replace Operations
120131
~~~~~~~~~~~~~~~~~~
121132

122133
A replace operation removes all fields and values of a specified document and
123-
replaces them with new ones. To perform a replace operation, create an instance
124-
of ``ReplaceOne`` and pass it a query filter and the fields and values you want
125-
to store in the matching document.
134+
replaces them with new fields and values that you specify. To perform a
135+
replace operation, create an instance of ``ReplaceOneModel`` and pass a
136+
query filter and the fields and values you want to replace the matching
137+
document with.
126138

127-
The following example creates an instance of ``ReplaceOne``:
139+
The following example creates an instance of ``ReplaceOneModel``:
128140

129141
.. literalinclude:: /includes/write/bulk.kt
130142
:start-after: start-bulk-replace-one
131143
:end-before: end-bulk-replace-one
132144
:language: kotlin
133145
:copyable:
134146

135-
To replace multiple documents, you must create an instance of ``ReplaceOne`` for each document.
147+
To replace multiple documents, you must create an instance of
148+
``ReplaceOneModel`` for each document.
136149

137150
Delete Operations
138151
~~~~~~~~~~~~~~~~~
139152

140-
To delete a document, create an instance of ``DeleteOne`` and pass in a
141-
query filter specifying the document you want to delete. ``DeleteOne`` removes
153+
To delete a document, create an instance of ``DeleteOneModel`` and pass a
154+
query filter specifying the document you want to delete. A
155+
``DeleteOneModel`` instance provides instructions to delete
142156
only *the first* document that matches your query filter.
143157

144-
The following example creates an instance of ``DeleteOne``:
158+
The following example creates an instance of ``DeleteOneModel``:
145159

146160
.. literalinclude:: /includes/write/bulk.kt
147161
:start-after: start-bulk-delete-one
148162
:end-before: end-bulk-delete-one
149163
:language: kotlin
150164
:copyable:
151165

152-
To delete multiple documents, create an instance of ``DeleteMany`` and pass in a
153-
query filter specifying the document you want to delete. ``DeleteMany`` removes
154-
*all* documents that match your query filter.
166+
To delete multiple documents, create an instance of ``DeleteManyModel`` and pass a
167+
query filter specifying the document you want to delete. An instance of
168+
``DeleteMany`` provides instructions to remove *all* documents that
169+
match your query filter.
155170

156171
The following example creates an instance of ``DeleteMany``:
157172

@@ -163,16 +178,16 @@ The following example creates an instance of ``DeleteMany``:
163178

164179
.. _kotlin-sync-bulkwrite-method:
165180

166-
Call the ``bulk_write()`` Method
167-
--------------------------------
181+
Call the bulkWrite() Method
182+
---------------------------
168183

169184
After you define a class instance for each operation you want to perform,
170-
pass a list of these instances to the ``bulk_write()`` method.
185+
pass a list of these instances to the ``bulkWrite()`` method.
171186
By default, the method runs the operations in the order
172-
they're defined in the list.
187+
that specified by the list of models.
173188

174189
The following example performs multiple write operations by using the
175-
``bulk_write()`` method:
190+
``bulkWrite()`` method:
176191

177192
.. io-code-block::
178193

@@ -183,7 +198,7 @@ The following example performs multiple write operations by using the
183198

184199
.. output::
185200

186-
BulkWriteResult({'writeErrors': [], 'writeConcernErrors': [], 'nInserted': 2, 'nUpserted': 0, 'nMatched': 2, 'nModified': 2, 'nRemoved': 1, 'upserted': []}, acknowledged=True)
201+
187202

188203
If any of the write operations fail, {+driver-short+} raises a
189204
``BulkWriteError`` and does not perform any further operations.
@@ -192,17 +207,20 @@ that failed, and details about the exception.
192207

193208
.. note::
194209

195-
When {+driver-short+} runs a bulk operation, it uses the ``write_concern`` of the
196-
collection in which the operation is running. The driver reports all write
197-
concern errors after attempting all operations, regardless of execution order.
210+
When the driver runs a bulk operation, it uses the write concern of the
211+
target collection. The driver reports all write concern errors after
212+
attempting all operations, regardless of execution order.
198213

199214
Customize Bulk Write Operations
200215
-------------------------------
201216

202-
The ``bulk_write()`` method optionally accepts additional
203-
parameters, which represent options you can use to configure the bulk write
204-
operation. If you don't specify any additional options, the driver does not customize
205-
the bulk write operation.
217+
The ``bulkWrite()`` method optionally accepts a parameter which
218+
specifies options you can use to configure the bulk write
219+
operation. If you don't specify any options, the driver performs the
220+
bulk operation with default settings.
221+
222+
The following table describes the setter methods that you can use to
223+
configure a ``BulkWriteOptions`` instance:
206224

207225
.. list-table::
208226
:widths: 30 70
@@ -211,60 +229,54 @@ the bulk write operation.
211229
* - Property
212230
- Description
213231

214-
* - ``ordered``
215-
- | If ``True``, the driver performs the write operations in the order
232+
* - ``ordered()``
233+
- | If ``true``, the driver performs the write operations in the order
216234
provided. If an error occurs, the remaining operations are not
217235
attempted.
218236
|
219-
| If ``False``, the driver performs the operations in an
237+
| If ``false``, the driver performs the operations in an
220238
arbitrary order and attempts to perform all operations.
221-
| Defaults to ``True``.
239+
| Defaults to ``true``.
222240

223-
* - ``bypass_document_validation``
224-
- | Specifies whether the operation bypasses document-level validation. For more
225-
information, see :manual:`Schema
241+
* - ``bypassDocumentValidation()``
242+
- | Specifies whether the update operation bypasses document validation. This lets you
243+
update documents that don't meet the schema validation requirements, if any
244+
exist. For more information about schema validation, see :manual:`Schema
226245
Validation </core/schema-validation/#schema-validation>` in the MongoDB
227246
Server manual.
228-
| Defaults to ``False``.
247+
| Defaults to ``false``.
229248

230-
* - ``session``
231-
- | An instance of ``ClientSession``. For more information, see the `API
232-
documentation <{+api-root+}pymongo/client_session.html#pymongo.client_session.ClientSession>`__.
249+
* - ``comment()``
250+
- | Sets a comment to attach to the operation.
233251

234-
* - ``comment``
235-
- | A comment to attach to the operation. For more information, see the :manual:`delete command
236-
fields </reference/command/delete/#command-fields>` guide in the
237-
{+mdb-server+} manual.
252+
* - ``let()``
253+
- | Provides a map of parameter names and values to set top-level
254+
variables for the operation. Values must be constant or closed
255+
expressions that don't reference document fields.
238256

239-
* - ``let``
240-
- | A map of parameter names and values. Values must be constant or closed
241-
expressions that don't reference document fields. For more information,
242-
see the :manual:`let statement
243-
</reference/command/delete/#std-label-delete-let-syntax>` in the
244-
{+mdb-server+} manual.
245-
246-
The following example calls the ``bulk_write()`` method from the preceding example, with the ``ordered`` option set
247-
to ``False``:
257+
The following code creates options and uses the ``ordered()`` method to
258+
specify an unordered bulk write. Then, the example uses the
259+
``bulkWrite()`` method to perform a bulk operation:
248260

249261
.. literalinclude:: /includes/write/bulk.kt
250262
:start-after: start-bulk-write-unordered
251263
:end-before: end-bulk-write-unordered
252264
:language: kotlin
253265
:copyable:
254266

255-
If any of the write operations in an unordered bulk write fail, {+driver-short+}
267+
If any of the write operations in an unordered bulk write fail, the {+driver-short+}
256268
reports the errors only after attempting all operations.
257269

258270
.. note::
259271

260-
Unordered bulk operations do not guarantee order of execution. The order can
272+
Unordered bulk operations do not guarantee an order of execution. The order can
261273
differ from the way you list them to optimize the runtime.
262274

263275
Return Value
264276
------------
265277

266-
The ``bulk_write()`` method returns a ``BulkWriteResult`` object. The
267-
``BulkWriteResult`` object contains the following properties:
278+
The ``bulkWrite()`` method returns a ``BulkWriteResult`` object. You can
279+
access the following information from a ``BulkWriteResult`` instance:
268280

269281
.. list-table::
270282
:widths: 30 70
@@ -273,53 +285,48 @@ The ``bulk_write()`` method returns a ``BulkWriteResult`` object. The
273285
* - Property
274286
- Description
275287

276-
* - ``acknowledged``
288+
* - ``wasAcknowledged()``
277289
- | Indicates if the server acknowledged the write operation.
278-
279-
* - ``bulk_api_result``
280-
- | The raw bulk API result returned by the server.
281290

282-
* - ``deleted_count``
291+
* - ``getDeletedCount()``
283292
- | The number of documents deleted, if any.
284293

285-
* - ``inserted_count``
294+
* - ``getInsertedCount()``
286295
- | The number of documents inserted, if any.
287296

288-
* - ``matched_count``
297+
* - ``getInserts()``
298+
- | The list of inserted documents, if any.
299+
300+
* - ``getMatchedCount()``
289301
- | The number of documents matched for an update, if applicable.
290302

291-
* - ``modified_count``
303+
* - ``getModifiedCount()``
292304
- | The number of documents modified, if any.
293305

294-
* - ``upserted_count``
295-
- | The number of documents upserted, if any.
296-
297-
* - ``upserted_ids``
298-
- | A map of the operation's index to the ``_id`` of the upserted documents, if
299-
applicable.
306+
* - ``getUpserts()``
307+
- | The list of upserted documents, if any.
300308

301309
Additional Information
302310
----------------------
303311

304312
To learn how to perform individual write operations, see the following guides:
305313

306-
- :ref:`pymongo-write-insert`
307-
- :ref:`pymongo-write-update`
308-
- :ref:`pymongo-write-replace`
309-
- :ref:`pymongo-write-delete`
314+
- :ref:`kotlin-sync-write-insert`
315+
- :ref:`kotlin-sync-write-update`
316+
- :ref:`kotlin-sync-write-delete`
317+
318+
.. - :ref:`kotlin-sync-write-replace`
310319

311320
API Documentation
312321
~~~~~~~~~~~~~~~~~
313322

314323
To learn more about any of the methods or types discussed in this
315324
guide, see the following API Documentation:
316325

317-
- `bulk_write() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.bulk_write>`__
318-
- `InsertOne <{+api-root+}pymongo/operations.html#pymongo.operations.InsertOne>`__
319-
- `UpdateOne <{+api-root+}pymongo/operations.html#pymongo.operations.UpdateOne>`__
320-
- `UpdateMany <{+api-root+}pymongo/operations.html#pymongo.operations.UpdateMany>`__
321-
- `ReplaceOne <{+api-root+}pymongo/operations.html#pymongo.operations.ReplaceOne>`__
322-
- `DeleteOne <{+api-root+}pymongo/operations.html#pymongo.operations.DeleteOne>`__
323-
- `DeleteMany <{+api-root+}pymongo/operations.html#pymongo.operations.DeleteMany>`__
324-
- `BulkWriteResult <{+api-root+}pymongo/results.html#pymongo.results.BulkWriteResult>`__
325-
- `BulkWriteError <{+api-root+}pymongo/errors.html#pymongo.errors.BulkWriteError>`__
326+
- `bulkWrite() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/bulk-write.html>`__
327+
- `DeleteManyModel <{+core-api+}/com/mongodb/client/model/DeleteManyModel.html>`__
328+
- `DeleteOneModel <{+core-api+}/com/mongodb/client/model/DeleteOneModel.html>`__
329+
- `InsertOneModel <{+core-api+}/com/mongodb/client/model/InsertOneModel.html>`__
330+
- `ReplaceOneModel <{+core-api+}/com/mongodb/client/model/ReplaceOneModel.html>`__
331+
- `UpdateManyModel <{+core-api+}/com/mongodb/client/model/UpdateManyModel.html>`__
332+
- `UpdateOneModel <{+core-api+}/com/mongodb/client/model/UpdateOneModel.html>`__

0 commit comments

Comments
 (0)