Skip to content

Commit 2da92fe

Browse files
committed
modify
1 parent 218137d commit 2da92fe

File tree

9 files changed

+110
-124
lines changed

9 files changed

+110
-124
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.
@@ -622,55 +622,28 @@ Even though the write operation inserting a document with a duplicate key result
622622
in an error, the other operations are executed because the write operation is
623623
unordered.
624624

625-
To learn more about the methods and classes mentioned in this section,
626-
see the following API documentation:
627-
628-
- `ClientBulkWriteOptions <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/bulk/ClientBulkWriteOptions.html>`__
629-
- `ClientBulkWriteResult <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/bulk/ClientBulkWriteResult.html>`__
630-
631-
Summary
632-
-------
633-
634-
``MongoCollection.bulkWrite()``
635-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
636-
637-
To perform a bulk operation, you create and pass a list of
638-
``WriteModel`` instances to the ``bulkWrite()`` method.
639-
640-
There are 6 different ``WriteModel`` subtypes: ``InsertOneModel``,
641-
``ReplaceOneModel``, ``UpdateOneModel``, ``UpdateManyModel``,
642-
``DeleteOneModel`` and ``DeleteManyModel``.
643-
644-
There are two ways to execute the ``bulkWrite()`` method:
645-
646-
- Ordered, which performs the bulk operations in order until an error occurs, if any
647-
- Unordered, which performs all the bulk operations in any order and reports errors
648-
at the end, if any
625+
API Documentation
626+
-----------------
649627

650-
To learn more about the collection ``bulkWrite`` command, see the
651-
:manual:`db.collection.bulkWrite() </reference/method/db.collection.bulkWrite/>`
652-
method reference in the {+mdb-server+} Manual.
628+
To learn more about the methods and classes used to perform bulk write
629+
operations in this section, see the following API documentation:
653630

654-
``MongoClient.bulkWrite()``
655-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
631+
MongoCollection
632+
~~~~~~~~~~~~~~~
656633

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

661-
To perform a client bulk operation, you create an pass a list of
662-
``ClientNamespacedWriteModel`` instances to this method.
638+
MongoClient
639+
~~~~~~~~~~~
663640

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

671-
The ``MongoClient.bulkWrite()`` method can also take a ``ClientBulkWriteOptions``
672-
object to specify different options for how the command is executed.
645+
Server Manual Entries
646+
---------------------
673647

674-
To learn more about the client ``bulkWrite`` command, see the
675-
:manual:`bulkWrite() </reference/command/bulkWrite/>` method reference in the {+mdb-server+}
676-
Manual.
648+
- :manual:`MongoCollection.bulkWrite() </reference/method/db.collection.bulkWrite/>`
649+
- :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 & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ The output of the preceding code resembles the following:
163163
60930c3aa982931c20ef6cd8]
164164

165165

166-
Insert Example
167-
--------------
166+
Insert Example: Full File
167+
-------------------------
168168

169169
The following code is a complete, standalone file that performs an insert one
170170
operation and an insert many operation.
@@ -184,12 +184,18 @@ operation and an insert many operation.
184184
InsertOne document id: BsonObjectId{value=...}
185185
InsertMany document ids: {0=BsonObjectId{value=...}, 1=BsonObjectId{value=...}}
186186

187-
More Information
188-
----------------
187+
API Documentation
188+
-----------------
189189

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

193-
- `insertMany() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#insertMany(java.util.List)>`__ API Documentation
194-
- `InsertManyResult <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/result/InsertManyResult.html>`__ API Documentation
195-
- Manual Explanation on :manual:`insertMany() </reference/method/db.collection.insertMany/>`
200+
- :manual:`db.collection.insertOne() </reference/method/db.collection.insertOne/>`
201+
- :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)