Skip to content

DOCSP-46391: client bulk write #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions snooty.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ driver-long = "MongoDB Java Reactive Streams Driver"
version = "5.3"
full-version = "{+version+}.0"
api = "https://mongodb.github.io/mongo-java-driver/{+version+}/apidocs"
rs-driver-api = "{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client"
core-api = "{+api+}/mongodb-driver-core/com/mongodb"
rs-docs = "https://www.reactive-streams.org/reactive-streams-1.0.4-javadoc/org/reactivestreams"
driver-source-gh = "https://github.com/mongodb/mongo-java-driver"
java-rs = "Java Reactive Streams"
Expand Down
2 changes: 1 addition & 1 deletion source/connect-to-mongo/choose-connection-target.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ API Documentation
To learn more about creating a ``MongoClient`` instance in the {+driver-short+},
see the following API documentation:

- `MongoClient <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoClients.html>`__
- `MongoClient <{+rs-driver-api+}/MongoClients.html>`__
8 changes: 4 additions & 4 deletions source/connect-to-mongo/connection-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Authentication

* - **authMechanism**
- | Sets the mechanism the {+driver-short+} uses to authenticate the
| application. Valid options are defined in the `Class ConnectionString <{+api+}/mongodb-driver-core/com/mongodb/ConnectionString.html>`__ API documentation.
| application. Valid options are defined in the `Class ConnectionString <{+core-api+}/ConnectionString.html>`__ API documentation.
|
| **Data Type**: {+string-data-type+}
| **Default**: ``"SCRAM-SHA-256"`` when connecting to MongoDB v4.0 or later.
Expand Down Expand Up @@ -376,15 +376,15 @@ Read Preference Configuration
| colon-separated key-value pairs, e.g. ``dc:ny,rack:1``.
| Spaces are stripped from beginning and end of all keys and values. To
| specify a list of tag sets, use multiple ``readPreferenceTags``, separated
| by semicolons. To learn more about ``readPreferenceTags``, see the `Class ConnectionString <{+api+}/mongodb-driver-core/com/mongodb/ConnectionString.html>`__ API documentation.
| by semicolons. To learn more about ``readPreferenceTags``, see the `Class ConnectionString <{+core-api+}/ConnectionString.html>`__ API documentation.
|
| **Data Type**: {+string-data-type+}
| **Default**: ``null``
| **Connection URI Example**: ``readPreferenceTags=dc:ny``

* - **maxStalenessSeconds**
- | Sets the maximum staleness in seconds. To learn more about staleness,
| see the `Class ConnectionString <{+api+}/mongodb-driver-core/com/mongodb/ConnectionString.html>`__ API documentation.
| see the `Class ConnectionString <{+core-api+}/ConnectionString.html>`__ API documentation.
|
| **Data Type**: ``Integer``
| **Default**: ``null``
Expand Down Expand Up @@ -471,7 +471,7 @@ SRV Configuration

* - **srvServiceName**
- | Sets the SRV service name. See
| the `ClusterSettings.getSrvServiceName() <{+api+}/mongodb-driver-core/com/mongodb/connection/ClusterSettings.html#getSrvServiceName()>`__
| the `ClusterSettings.getSrvServiceName() <{+core-api+}/connection/ClusterSettings.html#getSrvServiceName()>`__
| API documentation to learn more.
|
| **Data Type**: {+string-data-type+}
Expand Down
2 changes: 1 addition & 1 deletion source/connect-to-mongo/create-a-mongo-client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ API Documentation
To learn more about creating a ``MongoClient`` instance in the {+driver-short+},
see the following API documentation:

- `MongoClient <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoClients.html>`__
- `MongoClient <{+rs-driver-api+}/MongoClients.html>`__
6 changes: 3 additions & 3 deletions source/connect-to-mongo/network-compression.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ API Documentation
To learn more about any of the methods or types discussed in this
guide, see the following API documentation:

- `MongoClient <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoClient.html>`__
- `createSnappyCompressor() <{+api+}/mongodb-driver-core/com/mongodb/MongoCompressor.html#createSnappyCompressor()>`__
- `MongoClient <{+rs-driver-api+}/MongoClient.html>`__
- `createSnappyCompressor() <{+core-api+}/MongoCompressor.html#createSnappyCompressor()>`__
- `createZlibCompressor() <{+api+}//mongodb-driver-core/com/mongodb/MongoCompressor.html#createZlibCompressor()>`__
- `createZstdCompressor() <{+api+}/mongodb-driver-core/com/mongodb/MongoCompressor.html#createZstdCompressor()>`__
- `createZstdCompressor() <{+core-api+}/MongoCompressor.html#createZstdCompressor()>`__
14 changes: 7 additions & 7 deletions source/connect-to-mongo/stable-api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ API Documentation
For more information about using the {+stable-api+} with the {+driver-short+}, see the
following API documentation:

- `ServerApi <{+api+}/mongodb-driver-core/com/mongodb/ServerApi.html>`__
- `ServerApi.Builder <{+api+}/mongodb-driver-core/com/mongodb/ServerApi.Builder.html>`__
- `ServerApiVersion <{+api+}/mongodb-driver-core/com/mongodb/ServerApiVersion.html>`__
- `ServerAddress <{+api+}/mongodb-driver-core/com/mongodb/ServerAddress.html>`__
- `MongoClientSettings <{+api+}/mongodb-driver-core/com/mongodb/MongoClientSettings.html>`__
- `MongoClientSettings.Builder <{+api+}/mongodb-driver-core/com/mongodb/MongoClientSettings.Builder.html>`__
- `MongoClients <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoClients.html>`__
- `ServerApi <{+core-api+}/ServerApi.html>`__
- `ServerApi.Builder <{+core-api+}/ServerApi.Builder.html>`__
- `ServerApiVersion <{+core-api+}/ServerApiVersion.html>`__
- `ServerAddress <{+core-api+}/ServerAddress.html>`__
- `MongoClientSettings <{+core-api+}/MongoClientSettings.html>`__
- `MongoClientSettings.Builder <{+core-api+}/MongoClientSettings.Builder.html>`__
- `MongoClients <{+rs-driver-api+}/MongoClients.html>`__
2 changes: 1 addition & 1 deletion source/connect-to-mongo/tls.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Include the following import statements:

To instruct the driver to use
`io.netty.handler.ssl.SslContext <https://netty.io/4.1/api/io/netty/handler/ssl/SslContext.html>`__,
configure `NettyTransportSettings <{+api+}/mongodb-driver-core/com/mongodb/connection/NettyTransportSettings.html>`__
configure `NettyTransportSettings <{+core-api+}/connection/NettyTransportSettings.html>`__
when you define your ``MongoClientSettings``.

Use ``MongoClientSettings.Builder.transportSettings()``
Expand Down
12 changes: 6 additions & 6 deletions source/data-formats/time-series.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ To create a time series collection, pass the following parameters to the

- The name of the new collection to create

- A `CreateCollectionOptions <{+api+}/mongodb-driver-core/com/mongodb/client/model/CreateCollectionOptions.html>`__
object with the `TimeSeriesOptions <{+api+}/mongodb-driver-core/com/mongodb/client/model/TimeSeriesOptions.html>`__ set
- A `CreateCollectionOptions <{+core-api+}/client/model/CreateCollectionOptions.html>`__
object with the `TimeSeriesOptions <{+core-api+}/client/model/TimeSeriesOptions.html>`__ set
with the ``timeSeriesOptions()`` method

.. _java-rs-time-series-create-example:
Expand Down Expand Up @@ -165,7 +165,7 @@ API Documentation
To learn more about the methods mentioned in this guide, see the following
API documentation:

- `createCollection() <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoDatabase.html#createCollection(java.lang.String)>`__
- `listCollections() <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoDatabase.html#listCollections()>`__
- `insertOne() <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoCollection.html#insertOne(TDocument)>`__
- `insertMany() <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoCollection.html#insertMany(java.util.List)>`__
- `createCollection() <{+rs-driver-api+}/MongoDatabase.html#createCollection(java.lang.String)>`__
- `listCollections() <{+rs-driver-api+}/MongoDatabase.html#listCollections()>`__
- `insertOne() <{+rs-driver-api+}/MongoCollection.html#insertOne(TDocument)>`__
- `insertMany() <{+rs-driver-api+}/MongoCollection.html#insertMany(java.util.List)>`__
114 changes: 114 additions & 0 deletions source/includes/write/client-bulk-write.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package org.example;

import com.mongodb.*;
import com.mongodb.client.model.*;
import com.mongodb.client.model.bulk.*;
import org.bson.Document;

import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;

import com.mongodb.reactivestreams.client.MongoClient;
import com.mongodb.reactivestreams.client.MongoClients;

import java.util.*;

public class QuickStart {
public static void main(String[] args) {
// Replace the placeholder with your Atlas connection string
String uri = "<connection string>";

MongoClientSettings settings = MongoClientSettings.builder()
.applyConnectionString(new ConnectionString(uri))
.build();

// Create a new client and connect to the server
try (MongoClient mongoClient = MongoClients.create(settings)) {

// start-insert-models
ClientNamespacedInsertOneModel personToInsert = ClientNamespacedWriteModel
.insertOne(
new MongoNamespace("db", "people"),
new Document("name", "Julia Smith")
);

ClientNamespacedInsertOneModel thingToInsert = ClientNamespacedWriteModel
.insertOne(
new MongoNamespace("db", "things"),
new Document("object", "washing machine")
);
// end-insert-models

// start-replace-models
ClientNamespacedReplaceOneModel personReplacement = ClientNamespacedWriteModel
.replaceOne(
new MongoNamespace("db", "people"),
Filters.eq("_id", 1),
new Document("name", "Frederic Hilbert")
);

ClientNamespacedReplaceOneModel thingReplacement = ClientNamespacedWriteModel
.replaceOne(
new MongoNamespace("db", "things"),
Filters.eq("_id", 1),
new Document("object", "potato")
);
// end-replace-models

// start-perform
MongoNamespace peopleNamespace = new MongoNamespace("db", "people");
MongoNamespace thingsNamespace = new MongoNamespace("db", "things");

List<ClientNamespacedWriteModel> bulkOperations = Arrays.asList(
ClientNamespacedWriteModel
.insertOne(
peopleNamespace,
new Document("name", "Corey Kopper")
),
ClientNamespacedWriteModel
.replaceOne(
thingsNamespace,
Filters.eq("_id", 1),
new Document("object", "potato")
)
);

Publisher<ClientBulkWriteResult> bulkWritePublisher = mongoClient
.bulkWrite(bulkOperations);

ClientBulkWriteResult clientBulkResult = Mono
.from(bulkWritePublisher)
.block();

System.out.println(clientBulkResult.toString());
// end-perform

// start-options
MongoNamespace namespace = new MongoNamespace("db", "people");

ClientBulkWriteOptions options = ClientBulkWriteOptions
.clientBulkWriteOptions()
.ordered(false);

List<ClientNamespacedWriteModel> bulkOperations = Arrays.asList(
ClientNamespacedWriteModel.insertOne(
namespace,
new Document("_id", 1).append("name", "Rudra Suraj")
),
// Causes a duplicate key error
ClientNamespacedWriteModel.insertOne(
namespace,
new Document("_id", 1).append("name", "Mario Bianchi")
),
ClientNamespacedWriteModel.insertOne(
namespace,
new Document("name", "Wendy Zhang")
)
);

Publisher<ClientBulkWriteResult> bulkWritePublisher = mongoClient
.bulkWrite(bulkOperations, options);
// end-options
}
}
}
26 changes: 13 additions & 13 deletions source/monitoring.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The MongoDB Java driver organizes the events it defines into three categories:
The following sections show how to monitor each event category.

For a full list of the events you can monitor,
`see the event package of the MongoDB Java Driver <{+api+}/mongodb-driver-core/com/mongodb/event/package-summary.html>`__.
`see the event package of the MongoDB Java Driver <{+core-api+}/event/package-summary.html>`__.

.. _java-rs-command-events:

Expand Down Expand Up @@ -380,7 +380,7 @@ Oracle:

For more information about the ``JMXConnectionPoolListener`` class, see
the API Documentation for
`JMXConnectionPoolListener <{+api+}/mongodb-driver-core/com/mongodb/management/JMXConnectionPoolListener.html>`__.
`JMXConnectionPoolListener <{+core-api+}/management/JMXConnectionPoolListener.html>`__.

Include the Driver in Your Distributed Tracing System
-----------------------------------------------------
Expand Down Expand Up @@ -418,14 +418,14 @@ API Documentation
For more information about the classes and methods mentioned in this document, see
the following API Documentation:

- `MongoClients <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoClients.html>`__
- `MongoClientSettings <{+api+}/mongodb-driver-core/com/mongodb/MongoClientSettings.html>`__
- `CommandListener <{+api+}/mongodb-driver-core/com/mongodb/event/CommandListener.html>`__
- `CommandStartedEvent <{+api+}/mongodb-driver-core/com/mongodb/event/CommandStartedEvent.html>`__
- `CommandSucceededEvent <{+api+}/mongodb-driver-core/com/mongodb/event/CommandSucceededEvent.html>`__
- `CommandFailedEvent <{+api+}/mongodb-driver-core/com/mongodb/event/CommandFailedEvent.html>`__
- `ClusterListener <{+api+}/mongodb-driver-core/com/mongodb/event/ClusterListener.html>`__
- `ClusterDescriptionChangedEvent <{+api+}/mongodb-driver-core/com/mongodb/event/ClusterDescriptionChangedEvent.html>`__
- `ConnectionPoolListener <{+api+}/mongodb-driver-core/com/mongodb/event/ConnectionPoolListener.html>`__
- `ConnectionCheckedOutEvent <{+api+}/mongodb-driver-core/com/mongodb/event/ConnectionCheckedOutEvent.html>`__
- `ConnectionCheckOutFailedEvent <{+api+}/mongodb-driver-core/com/mongodb/event/ConnectionCheckOutFailedEvent.html>`__
- `MongoClients <{+rs-driver-api+}/MongoClients.html>`__
- `MongoClientSettings <{+core-api+}/MongoClientSettings.html>`__
- `CommandListener <{+core-api+}/event/CommandListener.html>`__
- `CommandStartedEvent <{+core-api+}/event/CommandStartedEvent.html>`__
- `CommandSucceededEvent <{+core-api+}/event/CommandSucceededEvent.html>`__
- `CommandFailedEvent <{+core-api+}/event/CommandFailedEvent.html>`__
- `ClusterListener <{+core-api+}/event/ClusterListener.html>`__
- `ClusterDescriptionChangedEvent <{+core-api+}/event/ClusterDescriptionChangedEvent.html>`__
- `ConnectionPoolListener <{+core-api+}/event/ConnectionPoolListener.html>`__
- `ConnectionCheckedOutEvent <{+core-api+}/event/ConnectionCheckedOutEvent.html>`__
- `ConnectionCheckOutFailedEvent <{+core-api+}/event/ConnectionCheckOutFailedEvent.html>`__
16 changes: 8 additions & 8 deletions source/read-write-configuration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ To learn more about any of the methods or types discussed in this
guide, see the following API documentation:

- `WriteConcern <{+api+}//mongodb-driver-core/com/mongodb/WriteConcern.html>`__
- `MongoDatabase.withWriteConcern <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoDatabase.html#withWriteConcern(com.mongodb.WriteConcern)>`__
- `MongoCollection.withWriteConcern <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoCollection.html#withWriteConcern(com.mongodb.WriteConcern)>`__
- `ReadConcern <{+api+}/mongodb-driver-core/com/mongodb/ReadConcern.html>`__
- `MongoDatabase.withReadConcern <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoDatabase.html#withReadConcern(com.mongodb.ReadConcern)>`__
- `MongoCollection.withReadConcern <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoCollection.html#withReadPreference(com.mongodb.ReadPreference)>`__
- `ReadPreference <{+api+}/mongodb-driver-core/com/mongodb/ReadPreference.html>`__
- `MongoDatabase.withReadPreference <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoDatabase.html#withReadPreference(com.mongodb.ReadPreference)>`__
- `MongoDatabase.withReadPreference <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoCollection.html#withReadPreference(com.mongodb.ReadPreference)>`__
- `MongoDatabase.withWriteConcern <{+rs-driver-api+}/MongoDatabase.html#withWriteConcern(com.mongodb.WriteConcern)>`__
- `MongoCollection.withWriteConcern <{+rs-driver-api+}/MongoCollection.html#withWriteConcern(com.mongodb.WriteConcern)>`__
- `ReadConcern <{+core-api+}/ReadConcern.html>`__
- `MongoDatabase.withReadConcern <{+rs-driver-api+}/MongoDatabase.html#withReadConcern(com.mongodb.ReadConcern)>`__
- `MongoCollection.withReadConcern <{+rs-driver-api+}/MongoCollection.html#withReadPreference(com.mongodb.ReadPreference)>`__
- `ReadPreference <{+core-api+}/ReadPreference.html>`__
- `MongoDatabase.withReadPreference <{+rs-driver-api+}/MongoDatabase.html#withReadPreference(com.mongodb.ReadPreference)>`__
- `MongoDatabase.withReadPreference <{+rs-driver-api+}/MongoCollection.html#withReadPreference(com.mongodb.ReadPreference)>`__
8 changes: 4 additions & 4 deletions source/read/change-streams.txt
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ API Documentation
To learn more about any of the methods or types discussed in this
guide, see the following API documentation:

- `MongoClient.watch() <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoClient.html#watch()>`__
- `MongoCollection.watch() <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoCollection.html#watch()>`__
- `MongoDatabase.watch() <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoDatabase.html#watch()>`__
- `ChangeStreamPublisher <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/ChangeStreamPublisher.html>`__
- `MongoClient.watch() <{+rs-driver-api+}/MongoClient.html#watch()>`__
- `MongoCollection.watch() <{+rs-driver-api+}/MongoCollection.html#watch()>`__
- `MongoDatabase.watch() <{+rs-driver-api+}/MongoDatabase.html#watch()>`__
- `ChangeStreamPublisher <{+rs-driver-api+}/ChangeStreamPublisher.html>`__
6 changes: 3 additions & 3 deletions source/read/count-documents.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,6 @@ API Documentation
To learn more about any of the methods or types discussed in this
guide, see the following API documentation:

- `countDocuments() <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoCollection.html#countDocuments()>`__
- `estimatedDocumentCount() <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoCollection.html#estimatedDocumentCount()>`__
- `Collation <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/FindPublisher.html#collation(com.mongodb.client.model.Collation)>`__
- `countDocuments() <{+rs-driver-api+}/MongoCollection.html#countDocuments()>`__
- `estimatedDocumentCount() <{+rs-driver-api+}/MongoCollection.html#estimatedDocumentCount()>`__
- `Collation <{+rs-driver-api+}/FindPublisher.html#collation(com.mongodb.client.model.Collation)>`__
Loading
Loading