Skip to content

Commit 9b036b3

Browse files
committed
Merge remote-tracking branch 'upstream/master' into DOCSP-47273-faq-reorg
2 parents 7cdf2b8 + 886a04c commit 9b036b3

24 files changed

+1528
-1183
lines changed

snooty.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ toc_landing_pages = [
1212
"/crud",
1313
"/crud/builders",
1414
"/data-formats",
15-
"/api-documentation"
15+
"/api-documentation",
16+
"/security/auth"
1617
]
1718

1819
sharedinclude_root = "https://raw.githubusercontent.com/10gen/docs-shared/main/"

source/connection.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Learn how to set up a connection and specify connection behavior from your
2828
application to a MongoDB deployment using the driver in the following
2929
sections:
3030

31-
- :ref:`Connect to MongoDB <connect-to-mongodb>`
31+
- :ref:`Connect to MongoDB <java-connect-to-mongodb>`
3232
- :ref:`View a List of Connection Options <connection-options>`
3333
- :ref:`Specify Connection Behavior with the MongoClient Class <specify-mongoclient-settings>`
3434
- :ref:`Enable Network Compression <network-compression>`
@@ -38,4 +38,4 @@ sections:
3838
- :atlas:`Connect to MongoDB Atlas from AWS Lambda </manage-connections-aws-lambda/>`
3939

4040
For information about authenticating with a MongoDB instance,
41-
see :ref:`<authentication-mechanisms>` and :ref:`<enterprise-authentication-mechanisms>`.
41+
see the :ref:`<java-authentication-mechanisms>` section.

source/connection/connect.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _connect-to-mongodb:
1+
.. _java-connect-to-mongodb:
22

33
==================
44
Connect to MongoDB
@@ -40,8 +40,8 @@ Use the ``MongoClients.create()`` method to construct a ``MongoClient``.
4040
As each ``MongoClient`` represents a thread-safe pool of connections to the
4141
database, most applications only require a single instance of a
4242
``MongoClient``, even across multiple threads.
43-
All resource usage limits, such as max connections, apply to individual
44-
``MongoClient`` instances.
43+
All resource usage limits, such as max connections, apply to individual
44+
``MongoClient`` instances.
4545

4646
To learn about the different settings you can use to control the
4747
behavior of your ``MongoClient``, see the guide on

source/connection/connection-troubleshooting.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ Connection Troubleshooting
103103

104104
.. replacement:: authentication-guide-reference
105105

106-
To learn more about specifying authentication mechanisms, see the :ref:`authentication-mechanisms` and
107-
:ref:`enterprise-authentication-mechanisms` guides.
106+
To learn more about specifying authentication mechanisms, see the :ref:`java-authentication-mechanisms`
107+
section.
108108

109109
.. replacement:: verify-authentication-mechanism-anchor
110110

source/connection/mongoclientsettings.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ connection behavior:
116116
messages to the server.
117117

118118
* - ``credential()``
119-
- Sets the :ref:`credential <authentication-mechanisms-java>`.
119+
- Sets the :ref:`credential <java-authentication-mechanisms>`.
120120

121121
* - ``readConcern()``
122122
- Sets the :manual:`read concern </reference/read-concern/>`.

source/crud/aggregation.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Connect to a MongoDB Deployment
114114
.. tip::
115115

116116
To learn more about connecting to MongoDB, see the :ref:`Connection
117-
Guide <connect-to-mongodb>`.
117+
Guide <java-connect-to-mongodb>`.
118118

119119
Insert Sample Data
120120
++++++++++++++++++

source/crud/transactions.txt

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,10 @@ error, the driver cancels the transaction and discards all data changes
2828
before they ever become visible.
2929

3030
In MongoDB, transactions run within logical **sessions**. A
31-
:manual:`session </reference/server-sessions/>` is a grouping of related
32-
read or write operations that you intend to run sequentially. Sessions
33-
enable :manual:`causal consistency
34-
</core/read-isolation-consistency-recency/#causal-consistency>` for a
35-
group of operations or allow you to execute operations in an
36-
:website:`ACID transaction </basics/acid-transactions>`. MongoDB
37-
guarantees that the data involved in your transaction operations remains
38-
consistent, even if the operations encounter unexpected errors.
31+
session is a grouping of related read or write operations that you
32+
intend to run sequentially. Sessions allow you to run operations
33+
in an ACID-compliant transaction, which is a transaction that meets
34+
an expectation of atomicity, consistency, isolation, and durability.
3935

4036
When using the {+driver-short+}, you can create a new session from a
4137
``MongoClient`` instance as a ``ClientSession`` type. We recommend that you reuse
@@ -54,6 +50,35 @@ instantiating a new client each time.
5450
You must include the ``session`` as a parameter for any operations that you
5551
want to include in a transaction.
5652

53+
Causal Consistency
54+
~~~~~~~~~~~~~~~~~~
55+
56+
.. sharedinclude:: dbx/causal-consistency.rst
57+
58+
.. replacement:: insert-one-method
59+
60+
``insertOne()``
61+
62+
.. replacement:: update-one-method
63+
64+
``updateOne()``
65+
66+
.. replacement:: find-one-method
67+
68+
``find()``
69+
70+
.. replacement:: delete-one-method
71+
72+
``deleteOne()``
73+
74+
.. replacement:: majority-rc
75+
76+
``MAJORITY``
77+
78+
.. replacement:: majority-wc
79+
80+
``MAJORITY``
81+
5782
Methods
5883
-------
5984

source/crud/write-operations/bulk.txt

Lines changed: 68 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Example
9696
The following example creates an ``InsertOneModel`` for two documents
9797
describing people:
9898

99-
.. literalinclude:: /includes/fundamentals/code-snippets/BulkWrite.java
99+
.. literalinclude:: /includes/fundamentals/code-snippets/bulk-write/BulkWrite.java
100100
:language: java
101101
:dedent:
102102
:start-after: begin insertDocumentsExample
@@ -111,7 +111,7 @@ describing people:
111111
The following example tries to insert two documents where the ``_id`` is
112112
``1`` and ``3``:
113113

114-
.. literalinclude:: /includes/fundamentals/code-snippets/BulkWrite.java
114+
.. literalinclude:: /includes/fundamentals/code-snippets/bulk-write/BulkWrite.java
115115
:language: java
116116
:dedent:
117117
:start-after: begin insertExceptionExample
@@ -156,7 +156,7 @@ The following example creates a ``ReplaceOneModel`` to
156156
replace a document where the ``_id`` is ``1`` with a document that
157157
contains an added ``location`` field:
158158

159-
.. literalinclude:: /includes/fundamentals/code-snippets/BulkWrite.java
159+
.. literalinclude:: /includes/fundamentals/code-snippets/bulk-write/BulkWrite.java
160160
:language: java
161161
:dedent:
162162
:start-after: begin replaceDocumentsExample
@@ -165,7 +165,7 @@ contains an added ``location`` field:
165165
If multiple documents match the query filter specified in
166166
the ``ReplaceOneModel`` instance, the operation replaces the first
167167
result. You can specify a sort in a ``ReplaceOptions`` instance to apply
168-
an order to matched documents before the driver performs the replace
168+
an order to matched documents before the server performs the replace
169169
operation, as shown in the following code:
170170

171171
.. code-block:: java
@@ -207,7 +207,7 @@ Example
207207
The following example creates an ``UpdateOneModel`` to update
208208
the ``age`` field in a document where the ``_id`` is ``2``:
209209

210-
.. literalinclude:: /includes/fundamentals/code-snippets/BulkWrite.java
210+
.. literalinclude:: /includes/fundamentals/code-snippets/bulk-write/BulkWrite.java
211211
:language: java
212212
:dedent:
213213
:start-after: begin updateDocumentsExample
@@ -216,7 +216,7 @@ the ``age`` field in a document where the ``_id`` is ``2``:
216216
If multiple documents match the query filter specified in
217217
the ``UpdateOneModel`` instance, the operation updates the first
218218
result. You can specify a sort in an ``UpdateOptions`` instance to apply
219-
an order to matched documents before the driver performs the update
219+
an order to matched documents before the server performs the update
220220
operation, as shown in the following code:
221221

222222
.. code-block:: java
@@ -260,7 +260,7 @@ Example
260260
The following example creates a ``DeleteOneModel`` to delete
261261
a document where the ``_id`` is ``1``:
262262

263-
.. literalinclude:: /includes/fundamentals/code-snippets/BulkWrite.java
263+
.. literalinclude:: /includes/fundamentals/code-snippets/bulk-write/BulkWrite.java
264264
:language: java
265265
:dedent:
266266
:start-after: begin deleteDocumentsExample
@@ -301,7 +301,7 @@ The following example performs these bulk operations:
301301
changes the ``name`` to ``"Zaynab Hassan"``
302302
- An operation that deletes all documents where the ``age`` value is greater than ``50``
303303

304-
.. literalinclude:: /includes/fundamentals/code-snippets/BulkWrite.java
304+
.. literalinclude:: /includes/fundamentals/code-snippets/bulk-write/BulkWrite.java
305305
:language: java
306306
:dedent:
307307
:start-after: begin bulkWriteExample
@@ -328,7 +328,7 @@ the bulk operation reports them at the end.
328328
Adding to the preceding example, including the following specifies the bulk
329329
operations to execute in any order:
330330

331-
.. literalinclude:: /includes/fundamentals/code-snippets/BulkWrite.java
331+
.. literalinclude:: /includes/fundamentals/code-snippets/bulk-write/BulkWrite.java
332332
:language: java
333333
:dedent:
334334
:start-after: begin bulkWriteNotOrderedExample
@@ -479,6 +479,8 @@ see the following API documentation:
479479
<{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/bulk/ClientNamespacedWriteModel.html>`__
480480
- `MongoNamespace <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoNamespace.html>`__
481481

482+
.. _java-sync-client-bulk-write-insert:
483+
482484
Insert Example
483485
~~~~~~~~~~~~~~
484486

@@ -488,63 +490,77 @@ the other document is inserted into the ``db.things`` collection.
488490
The ``MongoNamespace`` instance defines the databases and collections that
489491
each write operation applies to.
490492

491-
.. code-block:: java
493+
.. literalinclude:: /includes/fundamentals/code-snippets/bulk-write/ClientBulkWrite.java
494+
:language: java
495+
:dedent:
496+
:start-after: start-insert-models
497+
:end-before: end-insert-models
492498

493-
MongoNamespace peopleNamespace = new MongoNamespace("db", "people");
494-
MongoNamespace thingsNamespace = new MongoNamespace("db", "things");
499+
.. _java-sync-client-bulk-write-update:
495500

496-
List<ClientNamespacedWriteModel> bulkOperations = new ArrayList<>();
501+
Update Example
502+
~~~~~~~~~~~~~~
497503

498-
bulkOperations.add(ClientNamespacedWriteModel
499-
.insertOne(
500-
peopleNamespace,
501-
new Document("name", "Julia Smith")
502-
)
503-
);
504+
The following example shows how to use the ``bulkWrite()`` method to update
505+
existing documents in the ``db.people`` and ``db.things`` collections:
504506

505-
bulkOperations.add(ClientNamespacedWriteModel
506-
.insertOne(
507-
thingsNamespace,
508-
new Document("object", "washing machine")
509-
)
510-
);
507+
.. literalinclude:: /includes/fundamentals/code-snippets/bulk-write/ClientBulkWrite.java
508+
:language: java
509+
:dedent:
510+
:start-after: start-update-models
511+
:end-before: end-update-models
511512

512-
ClientBulkWriteResult result = mongoClient.bulkWrite(bulkOperations);
513+
This example increments the value of the ``age`` field by ``1`` in the
514+
document that has a ``name`` value of ``"Freya Polk"`` in the ``people``
515+
collection. It also sets the value of the ``manufacturer`` field to
516+
``"Premium Technologies"`` in all documents that have a ``category``
517+
value of ``"electronic"`` in the ``things`` collection.
513518

514-
Replace Example
515-
~~~~~~~~~~~~~~~
516-
517-
The following example shows how to use the ``bulkWrite()`` method to replace
518-
existing documents in the ``db.people`` and ``db.things`` collections.
519+
If multiple documents match the query filter specified in
520+
a ``ClientNamespacedUpdateOneModel`` instance, the operation updates the
521+
first result. You can specify a sort order in a `ClientUpdateOneOptions
522+
<{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/bulk/ClientUpdateOneOptions.html>`__
523+
instance to apply an order to matched documents before the driver
524+
performs the update operation, as shown in the following code:
519525

520526
.. code-block:: java
521527

522-
MongoNamespace peopleNamespace = new MongoNamespace("db", "people");
523-
MongoNamespace thingsNamespace = new MongoNamespace("db", "things");
528+
ClientUpdateOneOptions options = ClientUpdateOneOptions
529+
.clientUpdateOneOptions()
530+
.sort(Sorts.ascending("_id"));
524531

525-
List<ClientNamespacedWriteModel> bulkOperations = new ArrayList<>();
532+
.. _java-sync-client-bulk-write-replace:
526533

527-
bulkOperations.add(ClientNamespacedWriteModel.replaceOne(
528-
peopleNamespace,
529-
Filters.eq("_id", 1),
530-
new Document("name", "Frederic Hilbert")
531-
)
532-
);
534+
Replace Example
535+
~~~~~~~~~~~~~~~
533536

534-
bulkOperations.add(ClientNamespacedWriteModel.replaceOne(
535-
thingsNamespace,
536-
Filters.eq("_id", 1),
537-
new Document("object", "potato")
538-
)
539-
);
537+
The following example shows how to use the ``bulkWrite()`` method to replace
538+
existing documents in the ``db.people`` and ``db.things`` collections:
540539

541-
ClientBulkWriteResult result = mongoClient.bulkWrite(bulkOperations);
540+
.. literalinclude:: /includes/fundamentals/code-snippets/bulk-write/ClientBulkWrite.java
541+
:language: java
542+
:dedent:
543+
:start-after: start-replace-models
544+
:end-before: end-replace-models
542545

543546
After this example runs successfully, the document that has an ``_id`` value of ``1``
544547
in the ``people`` collection is replaced with a new document. The document in
545548
the ``things`` collection that has an ``_id`` value of ``1``
546549
is replaced with a new document.
547550

551+
If multiple documents match the query filter specified in
552+
a ``ClientNamespacedReplaceOneModel`` instance, the operation replaces the
553+
first result. You can specify a sort order in a `ClientReplaceOneOptions
554+
<{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/bulk/ClientReplaceOneOptions.html>`__
555+
instance to apply an order to matched documents before the driver
556+
performs the replace operation, as shown in the following code:
557+
558+
.. code-block:: java
559+
560+
ClientReplaceOneOptions options = ClientReplaceOneOptions
561+
.clientReplaceOneOptions()
562+
.sort(Sorts.ascending("_id"));
563+
548564
.. _java-sync-client-bulk-write-options:
549565

550566
Bulk Write Options
@@ -568,39 +584,11 @@ The following code sets the ``ordered()`` method on an
568584
instance of ``ClientBulkWriteOptions`` and performs a bulk write operation to
569585
insert multiple documents.
570586

571-
.. code-block:: java
572-
573-
MongoNamespace namespace = new MongoNamespace("db", "people");
574-
575-
ClientBulkWriteOptions options = ClientBulkWriteOptions
576-
.clientBulkWriteOptions()
577-
.ordered(false);
578-
579-
List<ClientNamespacedWriteModel> bulkOperations = new ArrayList<>();
580-
581-
bulkOperations.add(
582-
ClientNamespacedWriteModel.insertOne(
583-
namespace,
584-
new Document("_id", 1).append("name", "Rudra Suraj")
585-
)
586-
);
587-
588-
// Causes a duplicate key error
589-
bulkOperations.add(
590-
ClientNamespacedWriteModel.insertOne(
591-
namespace,
592-
new Document("_id", 1).append("name", "Mario Bianchi")
593-
)
594-
);
595-
596-
bulkOperations.add(
597-
ClientNamespacedWriteModel.insertOne(
598-
namespace,
599-
new Document("name", "Wendy Zhang")
600-
)
601-
);
602-
603-
ClientBulkWriteResult result = mongoClient.bulkWrite(bulkOperations, options);
587+
.. literalinclude:: /includes/fundamentals/code-snippets/bulk-write/ClientBulkWrite.java
588+
:language: java
589+
:dedent:
590+
:start-after: start-order-exec
591+
:end-before: end-order-exec
604592

605593
Even though the write operation inserting a document with a duplicate key results
606594
in an error, the other operations are executed because the write operation is

source/crud/write-operations/modify.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ The following example demonstrates how to change the value of the
102102
If multiple documents match the query filter specified in
103103
the ``updateOne()`` method, it updates the first result. You can
104104
specify a sort in an ``UpdateOptions`` instance to apply an order to
105-
matched documents before the driver performs the update operation, as
105+
matched documents before the server performs the update operation, as
106106
shown in the following code:
107107

108108
.. literalinclude:: /includes/fundamentals/code-snippets/Update.java
@@ -234,7 +234,7 @@ The following shows the updated document:
234234
If multiple documents match the query filter specified in
235235
the ``replaceOne()`` method, it replaces the first result. You can
236236
specify a sort in a ``ReplaceOptions`` instance to apply an order to
237-
matched documents before the driver performs the replace operation, as
237+
matched documents before the server performs the replace operation, as
238238
shown in the following code:
239239

240240
.. literalinclude:: /includes/fundamentals/code-snippets/Update.java

0 commit comments

Comments
 (0)