Skip to content

Commit b4c3142

Browse files
committed
modify
1 parent c97a9f3 commit b4c3142

File tree

9 files changed

+110
-125
lines changed

9 files changed

+110
-125
lines changed

source/crud/write-operations/bulk.txt

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,8 @@ see the following API documentation:
360360
- `ordered() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/BulkWriteOptions.html#ordered(boolean)>`__
361361

362362

363-
BulkWrite Example
364-
~~~~~~~~~~~~~~~~~
363+
BulkWrite Example: Full File
364+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
365365

366366
The following code is a complete, standalone file that performs an ordered bulk
367367
write operation.
@@ -634,55 +634,28 @@ Even though the write operation inserting a document with a duplicate key result
634634
in an error, the other operations are executed because the write operation is
635635
unordered.
636636

637-
To learn more about the methods and classes mentioned in this section,
638-
see the following API documentation:
639-
640-
- `ClientBulkWriteOptions <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/bulk/ClientBulkWriteOptions.html>`__
641-
- `ClientBulkWriteResult <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/bulk/ClientBulkWriteResult.html>`__
642-
643-
Summary
644-
-------
645-
646-
``MongoCollection.bulkWrite()``
647-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
648-
649-
To perform a bulk operation, you create and pass a list of
650-
``WriteModel`` instances to the ``bulkWrite()`` method.
651-
652-
There are 6 different ``WriteModel`` subtypes: ``InsertOneModel``,
653-
``ReplaceOneModel``, ``UpdateOneModel``, ``UpdateManyModel``,
654-
``DeleteOneModel`` and ``DeleteManyModel``.
655-
656-
There are two ways to execute the ``bulkWrite()`` method:
657-
658-
- Ordered, which performs the bulk operations in order until an error occurs, if any
659-
- Unordered, which performs all the bulk operations in any order and reports errors
660-
at the end, if any
637+
API Documentation
638+
-----------------
661639

662-
To learn more about the collection ``bulkWrite`` command, see the
663-
:manual:`db.collection.bulkWrite() </reference/method/db.collection.bulkWrite/>`
664-
method reference in the {+mdb-server+} Manual.
640+
To learn more about the methods and classes used to perform bulk write
641+
operations in this section, see the following API documentation:
665642

666-
``MongoClient.bulkWrite()``
667-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
643+
MongoCollection
644+
~~~~~~~~~~~~~~~
668645

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

673-
To perform a client bulk operation, you create an pass a list of
674-
``ClientNamespacedWriteModel`` instances to this method.
650+
MongoClient
651+
~~~~~~~~~~~
675652

676-
There are six subtypes of ``ClientNamespacedWriteModel`` that are used to
677-
represent write operations. To construct these write models, you can use the
678-
corresponding ``ClientNamespacedWriteModel`` methods ``insertOne()``, ``updateOne()``,
679-
``updateMany()``, ``replaceOne()``, ``deleteOne()``, and ``deleteMany()``. These
680-
methods take a ``MongoNamespace`` object that defines which
681-
database and collection to write to.
653+
- `bulkWrite() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCluster.html#bulkWrite(com.mongodb.client.ClientSession,java.util.List)>`__
654+
- `ClientBulkWriteOptions <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/bulk/ClientBulkWriteOptions.html>`__
655+
- `ClientBulkWriteResult <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/bulk/ClientBulkWriteResult.html>`__
682656

683-
The ``MongoClient.bulkWrite()`` method can also take a ``ClientBulkWriteOptions``
684-
object to specify different options for how the command is executed.
657+
Server Manual Entries
658+
---------------------
685659

686-
To learn more about the client ``bulkWrite`` command, see the
687-
:manual:`bulkWrite() </reference/command/bulkWrite/>` method reference in the {+mdb-server+}
688-
Manual.
660+
- :manual:`MongoCollection.bulkWrite() </reference/method/db.collection.bulkWrite/>`
661+
- :manual:`MongoClient.bulkWrite() </reference/command/bulkWrite/>`

source/crud/write-operations/delete.txt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ collection:
148148
{ "_id": 1, "color": "red", "qty": 5 }
149149
{ "_id": 8, "color": "black", "qty": 8 }
150150

151-
Delete Example
152-
--------------
151+
Delete Example: Full File
152+
-------------------------
153153

154154
The following code is a complete, standalone file that performs a delete one
155155
operation and a delete many operation.
@@ -174,14 +174,10 @@ API documentation.
174174
DeleteOne document count: 1
175175
DeleteMany document count: 4
176176

177-
More Information
178-
----------------
179-
180-
For more information about the methods and classes mentioned in this guide,
181-
see the following resources:
182-
183177
API Documentation
184-
~~~~~~~~~~~~~~~~~
178+
-----------------
179+
180+
For additional information on the methods and classes used to delete documents, see the following API Documentation:
185181

186182
- `deleteOne() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#deleteOne(org.bson.conversions.Bson)>`__
187183
- `deleteMany() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#deleteMany(org.bson.conversions.Bson)>`__
@@ -190,7 +186,7 @@ API Documentation
190186
- `FindOneAndDeleteOptions <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/FindOneAndDeleteOptions.html>`__
191187

192188
Server Manual Entries
193-
~~~~~~~~~~~~~~~~~~~~~
189+
---------------------
194190

195191
- :manual:`db.collection.deleteOne() </reference/method/db.collection.deleteMany/>`
196192
- :manual:`db.collection.deleteMany() </reference/method/db.collection.deleteOne/>`

source/crud/write-operations/insert.txt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ The output of the preceding code resembles the following:
161161
60930c3aa982931c20ef6cd8]
162162

163163

164-
Insert Example
165-
--------------
164+
Insert Example: Full File
165+
-------------------------
166166

167167
The following code is a complete, standalone file that performs an insert one
168168
operation and an insert many operation.
@@ -182,13 +182,18 @@ operation and an insert many operation.
182182
InsertOne document id: BsonObjectId{value=...}
183183
InsertMany document ids: {0=BsonObjectId{value=...}, 1=BsonObjectId{value=...}}
184184

185-
More Information
186-
----------------
185+
API Documentation
186+
-----------------
187187

188-
For more information about the methods and classes mentioned in this section,
189-
see the following resources:
188+
For additional information on the methods and classes used to insert documents, see the following API Documentation:
189+
190+
- `insertOne() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#insertOne(TDocument)>`__
191+
- `InsertOneResult <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/result/InsertOneResult.html>`__
192+
- `insertMany() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#insertMany(java.util.List)>`__
193+
- `InsertManyResult <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/result/InsertManyResult.html>`__
194+
195+
Server Manual Entries
196+
---------------------
190197

191-
- `insertMany() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#insertMany(java.util.List)>`__ API Documentation
192-
- `InsertManyResult <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/result/InsertManyResult.html>`__ API Documentation
193-
- Manual Explanation on :manual:`insertMany() </reference/method/db.collection.insertMany/>`
194-
- Runnable :doc:`Insert Multiple Documents Example </usage-examples/insertMany>`
198+
- :manual:`db.collection.insertOne() </reference/method/db.collection.insertOne/>`
199+
- :manual:`db.collection.insertMany() </reference/method/db.collection.insertMany/>`

source/crud/write-operations/modify.txt

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ documents match.
163163
see :manual:`Unique Indexes </core/index-unique/>` in the
164164
{+mdb-server+} manual.
165165

166-
Update Example
167-
~~~~~~~~~~~~~~
166+
Update Example: Full File
167+
~~~~~~~~~~~~~~~~~~~~~~~~~
168168

169169
The following code is a complete, standalone file that performs an update one
170170
operation and an update many operation.
@@ -181,8 +181,10 @@ operation and an update many operation.
181181
:language: none
182182
:visible: false
183183

184-
InsertOne document id: BsonObjectId{value=...}
185-
InsertMany document ids: {0=BsonObjectId{value=...}, 1=BsonObjectId{value=...}}
184+
UpdateOne modified document count: 1
185+
Upserted ID: null
186+
187+
UpdateMany modified document count: 242
186188

187189
.. _replace-operation:
188190

@@ -277,3 +279,54 @@ documents match.
277279
For more information about constraints on unique indexes,
278280
see :manual:`Unique Indexes </core/index-unique/>` in the
279281
{+mdb-server+} manual.
282+
283+
ReplaceOne Example: Full File
284+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285+
286+
The following code is a complete, standalone file that performs an update one
287+
operation and an update many operation.
288+
289+
.. include:: /includes/crud/example-intro.rst
290+
291+
.. io-code-block::
292+
293+
.. input:: /includes/crud/ReplaceOne.java
294+
:language: java
295+
:dedent:
296+
297+
.. output::
298+
:language: none
299+
:visible: false
300+
301+
UpdateOne modified document count: 1
302+
Upserted ID: null
303+
304+
UpdateMany modified document count: 242
305+
306+
API Documentation
307+
-----------------
308+
309+
For additional information on the methods and classes used to modify documents, see the following API Documentation:
310+
311+
- `updateOne() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#updateOne(org.bson.conversions.Bson,java.util.List,com.mongodb.client.model.UpdateOptions)>`__
312+
- `updateMany() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#updateMany(org.bson.conversions.Bson,java.util.List,com.mongodb.client.model.UpdateOptions)>`__
313+
- `UpdateOptions <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/UpdateOptions.html>`__
314+
- `replaceOne() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#replaceOne(org.bson.conversions.Bson,TDocument)>`__
315+
- `ReplaceOptions <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/ReplaceOptions.html?is-external=true>`__
316+
- - `UpdateResult <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/result/UpdateResult.html>`__
317+
318+
For additional information on the methods used in the examples on this
319+
page, see the following API Documentation:
320+
321+
- `eq() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/Filters.html#eq(java.lang.String,TItem)>`__
322+
- `combine() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/Updates.html#combine(org.bson.conversions.Bson...)>`__
323+
- `set() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/Updates.html#set(java.lang.String,TItem)>`__
324+
- `addToSet() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/Updates.html#addToSet(java.lang.String,TItem)>`__
325+
- `currentTimestamp() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/Updates.html#currentTimestamp(java.lang.String)>`__
326+
327+
Server Manual Entries
328+
---------------------
329+
330+
- :manual:`db.collection.updateOne() </reference/method/db.collection.updateOne/>`
331+
- :manual:`db.collection.updateMany() </reference/method/db.collection.updateMany/>`
332+
- :manual:`db.collection.replaceOne() </reference/method/db.collection.replaceOne/>`

source/includes/crud/Delete.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import com.mongodb.client.MongoDatabase;
1515
import com.mongodb.client.result.DeleteResult;
1616

17-
public class DeleteOne {
17+
import static com.mongodb.client.model.Filters.lt;
18+
19+
public class Delete {
1820

1921
public static void main(String[] args) {
2022
// Replace the uri string with your MongoDB deployment's connection string

source/includes/crud/Insert.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
import com.mongodb.client.result.InsertOneResult;
1616
import com.mongodb.client.result.InsertManyResult;
1717

18-
public class InsertOne {
18+
import java.util.List;
19+
20+
public class Insert {
1921
public static void main(String[] args) {
2022
// Replace the uri string with your MongoDB deployment's connection string
2123
String uri = "<connection string uri>";

source/includes/crud/Update.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import com.mongodb.client.model.Updates;
1515
import com.mongodb.client.result.UpdateResult;
1616

17-
public class UpdateOne {
17+
import static com.mongodb.client.model.Filters.gt;
18+
19+
public class Update {
1820

1921
public static void main(String[] args) {
2022
// Replace the uri string with your MongoDB deployment's connection string
@@ -41,8 +43,8 @@ public static void main(String[] args) {
4143
UpdateResult result = collection.updateOne(updateOneQuery, updateOneUpdates, options);
4244

4345
// Prints the number of updated documents and the upserted document ID, if an upsert was performed
44-
System.out.println("Modified document count: " + result.getModifiedCount());
45-
System.out.println("Upserted id: " + result.getUpsertedId());
46+
System.out.println("UpdateOne modified document count: " + result.getModifiedCount());
47+
System.out.println("Upserted ID: " + result.getUpsertedId());
4648

4749
// Prints a message if any exceptions occur during the operation
4850
} catch (MongoException me) {
@@ -61,7 +63,7 @@ public static void main(String[] args) {
6163
UpdateResult result = collection.updateMany(updateManyQuery, updateManyUpdates);
6264

6365
// Prints the number of updated documents
64-
System.out.println("Modified document count: " + result.getModifiedCount());
66+
System.out.println("\nUpdateMany modified document count: " + result.getModifiedCount());
6567

6668
// Prints a message if any exceptions occur during the operation
6769
} catch (MongoException me) {

source/includes/usage-examples/code-snippets/UpdateMany.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)