Skip to content

Commit c8042a9

Browse files
authored
Merge branch 'master' into DOCSP-48094-bom
2 parents 19ba1be + 0434019 commit c8042a9

32 files changed

+667
-1362
lines changed

source/crud/bulk.txt

+49-44
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,35 @@ see the following API documentation:
358358
- `BulkWriteOptions <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/BulkWriteOptions.html>`__
359359
- `ordered() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/BulkWriteOptions.html#ordered(boolean)>`__
360360

361+
.. _java-usage-bulkwrite:
362+
363+
Bulk Write Example: Full File
364+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
365+
366+
.. include:: /includes/crud/example-intro.rst
367+
368+
The following code is a complete, standalone file that performs the following
369+
actions:
370+
371+
#. Creates a list of instances of the ``InsertOneModel``, ``UpdateOneModel``,
372+
``DeleteOneModel``, and ``ReplaceOneModel`` classes.
373+
#. Runs an ordered ``bulkWrite()`` operation that performs the writes specified in the model list.
374+
375+
.. io-code-block::
376+
377+
.. input:: /includes/crud/BulkWrite.java
378+
:language: java
379+
:dedent:
380+
381+
.. output::
382+
:language: none
383+
:visible: false
384+
385+
Result statistics:
386+
inserted: 3
387+
updated: 2
388+
deleted: 1
389+
361390
.. _java-sync-client-bulk-write:
362391

363392
Client Bulk Write
@@ -594,55 +623,31 @@ Even though the write operation inserting a document with a duplicate key result
594623
in an error, the other operations are executed because the write operation is
595624
unordered.
596625

597-
To learn more about the methods and classes mentioned in this section,
598-
see the following API documentation:
626+
Additional Information
627+
----------------------
599628

600-
- `ClientBulkWriteOptions <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/bulk/ClientBulkWriteOptions.html>`__
601-
- `ClientBulkWriteResult <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/bulk/ClientBulkWriteResult.html>`__
602-
603-
Summary
604-
-------
605-
606-
``MongoCollection.bulkWrite()``
607-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
608-
609-
To perform a bulk operation, you create and pass a list of
610-
``WriteModel`` instances to the ``bulkWrite()`` method.
611-
612-
There are 6 different ``WriteModel`` subtypes: ``InsertOneModel``,
613-
``ReplaceOneModel``, ``UpdateOneModel``, ``UpdateManyModel``,
614-
``DeleteOneModel`` and ``DeleteManyModel``.
615-
616-
There are two ways to execute the ``bulkWrite()`` method:
617-
618-
- Ordered, which performs the bulk operations in order until an error occurs, if any
619-
- Unordered, which performs all the bulk operations in any order and reports errors
620-
at the end, if any
629+
API Documentation
630+
~~~~~~~~~~~~~~~~~
621631

622-
To learn more about the collection ``bulkWrite`` command, see the
623-
:manual:`db.collection.bulkWrite() </reference/method/db.collection.bulkWrite/>`
624-
method reference in the {+mdb-server+} Manual.
632+
To learn more about the methods and classes used to perform bulk write
633+
operations in this section, see the following API documentation:
625634

626-
``MongoClient.bulkWrite()``
627-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
635+
MongoCollection
636+
```````````````
628637

629-
When connecting to a deployment running {+mdb-server+} version 8.0 or later, you
630-
can use the ``MongoClient.bulkWrite()`` method to perform bulk operations on multiple
631-
databases and collections at once.
638+
- `bulkWrite() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#bulkWrite(com.mongodb.client.ClientSession,java.util.List)>`__
639+
- `BulkWriteOptions <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/BulkWriteOptions.html>`__
640+
- `MongoBulkWriteException <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoBulkWriteException.html>`__
632641

633-
To perform a client bulk operation, you create an pass a list of
634-
``ClientNamespacedWriteModel`` instances to this method.
642+
MongoClient
643+
```````````
635644

636-
There are six subtypes of ``ClientNamespacedWriteModel`` that are used to
637-
represent write operations. To construct these write models, you can use the
638-
corresponding ``ClientNamespacedWriteModel`` methods ``insertOne()``, ``updateOne()``,
639-
``updateMany()``, ``replaceOne()``, ``deleteOne()``, and ``deleteMany()``. These
640-
methods take a ``MongoNamespace`` object that defines which
641-
database and collection to write to.
645+
- `bulkWrite() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCluster.html#bulkWrite(com.mongodb.client.ClientSession,java.util.List)>`__
646+
- `ClientBulkWriteOptions <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/bulk/ClientBulkWriteOptions.html>`__
647+
- `ClientBulkWriteResult <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/bulk/ClientBulkWriteResult.html>`__
642648

643-
The ``MongoClient.bulkWrite()`` method can also take a ``ClientBulkWriteOptions``
644-
object to specify different options for how the command is executed.
649+
Server Manual Entries
650+
~~~~~~~~~~~~~~~~~~~~~
645651

646-
To learn more about the client ``bulkWrite`` command, see the
647-
:manual:`bulkWrite() </reference/command/bulkWrite/>` method reference in the {+mdb-server+}
648-
Manual.
652+
- :manual:`MongoCollection.bulkWrite() </reference/method/db.collection.bulkWrite/>`
653+
- :manual:`MongoClient.bulkWrite() </reference/command/bulkWrite/>`

source/crud/delete.txt

+59-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
Delete Documents
55
================
66

7+
.. facet::
8+
:name: genre
9+
:values: reference
10+
11+
.. meta::
12+
:keywords: remove, clear, reset, code example
13+
:description: Learn about how to delete documents in the {+driver-long+}.
14+
715
.. contents:: On this page
816
:local:
917
:backlinks: none
@@ -147,14 +155,54 @@ collection:
147155
{ "_id": 1, "color": "red", "qty": 5 }
148156
{ "_id": 8, "color": "black", "qty": 8 }
149157

150-
For more information about the methods and classes mentioned in this guide,
151-
see the following resources:
152-
153-
- `deleteOne() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#deleteOne(org.bson.conversions.Bson)>`__ API Documentation
154-
- `deleteMany() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#deleteMany(org.bson.conversions.Bson)>`__ API Documentation
155-
- `findOneAndDelete() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#findOneAndDelete(org.bson.conversions.Bson)>`__ API Documentation
156-
- `DeleteOptions <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/DeleteOptions.html>`__ API Documentation
157-
- `FindOneAndDeleteOptions <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/FindOneAndDeleteOptions.html>`__ API Documentation
158-
- :manual:`db.collection.deleteOne() </reference/method/db.collection.deleteMany/>` Server Manual Entry
159-
- :manual:`db.collection.deleteMany() </reference/method/db.collection.deleteOne/>` Server Manual Entry
160-
- :manual:`db.collection.findOneAndDelete() </reference/method/db.collection.findOneAndDelete/>` Server Manual Entry
158+
.. _java-usage-deletemany:
159+
.. _java-usage-deleteone:
160+
161+
Delete Example: Full File
162+
-------------------------
163+
164+
.. include:: /includes/crud/example-intro.rst
165+
166+
The following code is a complete, standalone file that performs a delete one
167+
operation and a delete many operation:
168+
169+
.. io-code-block::
170+
171+
.. input:: /includes/crud/Delete.java
172+
:language: java
173+
:dedent:
174+
175+
.. output::
176+
:language: none
177+
:visible: false
178+
179+
Deleted document count - query for one: 1
180+
Deleted document count - unlimited query: 4
181+
182+
183+
The queries in these examples use the ``eq()`` and ``lt()`` filters to query documents. For more
184+
information about filters, see the `Filters Class
185+
<{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/Filters.html>`__
186+
API documentation.
187+
188+
Additional Information
189+
----------------------
190+
191+
API Documentation
192+
~~~~~~~~~~~~~~~~~
193+
194+
For more information about the methods and classes used to delete documents, see the following API documentation:
195+
196+
- `deleteOne() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#deleteOne(org.bson.conversions.Bson)>`__
197+
- `deleteMany() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#deleteMany(org.bson.conversions.Bson)>`__
198+
- `findOneAndDelete() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#findOneAndDelete(org.bson.conversions.Bson)>`__
199+
- `DeleteOptions <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/DeleteOptions.html>`__
200+
- `FindOneAndDeleteOptions <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/FindOneAndDeleteOptions.html>`__
201+
- `DeleteResult <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/result/DeleteResult.html>`__
202+
203+
Server Manual Entries
204+
~~~~~~~~~~~~~~~~~~~~~
205+
206+
- :manual:`db.collection.deleteOne() </reference/method/db.collection.deleteOne/>`
207+
- :manual:`db.collection.deleteMany() </reference/method/db.collection.deleteMany/>`
208+
- :manual:`db.collection.findOneAndDelete() </reference/method/db.collection.findOneAndDelete/>`

source/crud/insert.txt

+59-34
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
Insert Operations
55
=================
66

7+
.. facet::
8+
:name: genre
9+
:values: reference
10+
11+
.. meta::
12+
:keywords: add, save, code example
13+
:description: Learn about how to insert documents in the {+driver-long+}.
14+
715
.. contents:: On this page
816
:local:
917
:backlinks: none
@@ -30,28 +38,23 @@ The following sections focus on ``insertOne()`` and
3038
method, see our
3139
:ref:`guide on Bulk Operations <java-fundamentals-bulkwrite>`.
3240

33-
A Note About ``_id``
34-
--------------------
35-
36-
When inserting a document, MongoDB enforces one constraint on your
37-
documents by default: each document *must* contain a unique ``_id``
38-
field.
41+
.. note:: The ``id_`` Field in Insert Operations
3942

40-
There are two ways to manage this field:
43+
When inserting a document, MongoDB enforces one constraint on your
44+
documents by default: each document *must* contain a unique ``_id`` value.
45+
Duplicate ``_id`` values violate unique index constraints, resulting in a
46+
``WriteError``.
4147

42-
- You can manage this field yourself, ensuring each value you use is unique.
43-
- You can let the driver automatically generate unique ObjectId values.
48+
There are two ways to manage this field:
4449

45-
Unless you have provided strong guarantees for uniqueness, we recommend
46-
you let the driver automatically generate ``_id`` values.
50+
- You can manage this field yourself, ensuring each value you use is unique.
51+
- You can let the driver automatically generate unique ObjectId values.
4752

48-
.. note::
49-
50-
Duplicate ``_id`` values violate unique index constraints, resulting
51-
in a ``WriteError``.
52-
53-
For additional information on unique indexes, see the manual entry on
54-
:manual:`Unique Indexes </core/index-unique/>`.
53+
Unless you have provided strong guarantees for uniqueness, we recommend
54+
you let the driver automatically generate ``_id`` values.
55+
56+
For more information about unique indexes, see the manual entry on
57+
:manual:`Unique Indexes </core/index-unique/>`.
5558

5659
.. _java-insertone:
5760

@@ -159,26 +162,48 @@ The output of the preceding code resembles the following:
159162
.. code-block::
160163
:copyable: false
161164

162-
Inserted documents with the following ids: [60930c3aa982931c20ef6cd7, 60930c3aa982931c20ef6cd8]
165+
Inserted documents with the following ids: [60930c3aa982931c20ef6cd7,
166+
60930c3aa982931c20ef6cd8]
163167

164-
For more information about the methods and classes mentioned in this section,
165-
see the following resources:
168+
.. _java-usage-insertmany:
169+
.. _java-usage-insertone:
170+
171+
Insert Example: Full File
172+
-------------------------
173+
174+
.. include:: /includes/crud/example-intro.rst
175+
176+
The following code is a complete, standalone file that performs an insert one
177+
operation and an insert many operation:
178+
179+
.. io-code-block::
180+
181+
.. input:: /includes/crud/Insert.java
182+
:language: java
183+
:dedent:
184+
185+
.. output::
186+
:language: none
187+
:visible: false
188+
189+
insertOne() document id: BsonObjectId{value=...}
190+
insertMany() document ids: {0=BsonObjectId{value=...}, 1=BsonObjectId{value=...}}
166191

167-
- `insertMany() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#insertMany(java.util.List)>`__ API Documentation
168-
- `InsertManyResult <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/result/InsertManyResult.html>`__ API Documentation
169-
- Manual Explanation on :manual:`insertMany() </reference/method/db.collection.insertMany/>`
170-
- Runnable :ref:`Insert Multiple Documents Example <java-usage-insertmany>`
192+
Additional Information
193+
----------------------
171194

172-
Summary
173-
-------
195+
API Documentation
196+
~~~~~~~~~~~~~~~~~
174197

175-
There are three ways to perform an insert operation, but we focused on two:
198+
For more information about the methods and classes used to insert documents, see the following API documentation:
176199

177-
- The ``insertOne()`` method inserts a single document.
178-
- The ``insertMany()`` method inserts multiple documents.
200+
- `insertOne() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#insertOne(TDocument)>`__
201+
- `InsertOneResult <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/result/InsertOneResult.html>`__
202+
- `insertMany() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#insertMany(java.util.List)>`__
203+
- `InsertManyResult <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/result/InsertManyResult.html>`__
179204

180-
Both methods automatically generate an ``_id`` if you omit the field in
181-
your document.
205+
Server Manual Entries
206+
~~~~~~~~~~~~~~~~~~~~~
182207

183-
If the insertion is successful, both methods return an instance
184-
representing the ``_id`` of each new document.
208+
- :manual:`db.collection.insertOne() </reference/method/db.collection.insertOne/>`
209+
- :manual:`db.collection.insertMany() </reference/method/db.collection.insertMany/>`

0 commit comments

Comments
 (0)