Skip to content

Commit de2efaf

Browse files
authored
DOCSP-41130: bulk write operations (mongodb#27)
* DOCSP-41130: bulk write * DOCSP-41130 * add code * add api references * dedent * MM PR fixes 1 + source constant edit
1 parent ae8646c commit de2efaf

18 files changed

+475
-50
lines changed

snooty.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ full-version = "{+version-number+}.2"
2727
version = "v{+version-number+}"
2828
mdb-server = "MongoDB Server"
2929
stable-api = "Stable API"
30-
api = "https://mongodb.github.io/mongo-java-driver/{+version-number+}/apidocs/mongodb-driver-kotlin-sync"
30+
api = "https://mongodb.github.io/mongo-java-driver/{+version-number+}/apidocs/mongodb-driver-kotlin-sync/mongodb-driver-kotlin-sync"
3131
java-api = "https://mongodb.github.io/mongo-java-driver/{+version-number+}"
32-
core-api = "{+java-api+}/apidocs/mongodb-driver-core/"
32+
core-api = "{+java-api+}/apidocs/mongodb-driver-core"
3333
kotlin-docs = "https://kotlinlang.org"

source/connect/stable-api.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ API Documentation
125125
For more information about using the {+stable-api+} with {+driver-short+}, see the
126126
following API documentation:
127127

128-
- `ServerApi <{+core-api+}com/mongodb/ServerApi.html>`__
129-
- `ServerApi.Builder <{+core-api+}com/mongodb/ServerApi.Builder.html>`__
130-
- `ServerApiVersion <{+core-api+}com/mongodb/ServerApiVersion.html>`__
131-
- `ServerAddress <{+core-api+}com/mongodb/ServerAddress.html>`__
132-
- `MongoClientSettings <{+core-api+}com/mongodb/MongoClientSettings.html>`__
133-
- `MongoClientSettings.Builder <{+core-api+}com/mongodb/MongoClientSettings.Builder.html>`__
134-
- `MongoClient <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-client/index.html>`__
135-
- `MongoClient.create() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-client/-factory/create.html>`__
128+
- `ServerApi <{+core-api+}/com/mongodb/ServerApi.html>`__
129+
- `ServerApi.Builder <{+core-api+}/com/mongodb/ServerApi.Builder.html>`__
130+
- `ServerApiVersion <{+core-api+}/com/mongodb/ServerApiVersion.html>`__
131+
- `ServerAddress <{+core-api+}/com/mongodb/ServerAddress.html>`__
132+
- `MongoClientSettings <{+core-api+}/com/mongodb/MongoClientSettings.html>`__
133+
- `MongoClientSettings.Builder <{+core-api+}/com/mongodb/MongoClientSettings.Builder.html>`__
134+
- `MongoClient <{+api+}/com.mongodb.kotlin.client/-mongo-client/index.html>`__
135+
- `MongoClient.create() <{+api+}/com.mongodb.kotlin.client/-mongo-client/-factory/create.html>`__

source/data-formats/time-series.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ API Documentation
175175
To learn more about the methods mentioned in this guide, see the following
176176
API documentation:
177177

178-
- `createCollection() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-database/create-collection.html>`__
179-
- `listCollections() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-database/list-collections.html>`__
180-
- `insertOne() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/insert-one.html>`__
181-
- `insertMany() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/insert-many.html>`__
178+
- `createCollection() <{+api+}/com.mongodb.kotlin.client/-mongo-database/create-collection.html>`__
179+
- `listCollections() <{+api+}/com.mongodb.kotlin.client/-mongo-database/list-collections.html>`__
180+
- `insertOne() <{+api+}/com.mongodb.kotlin.client/-mongo-collection/insert-one.html>`__
181+
- `insertMany() <{+api+}/com.mongodb.kotlin.client/-mongo-collection/insert-many.html>`__

source/includes/write/bulk.kt

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import com.mongodb.client.model.*
2+
import com.mongodb.client.model.Filters.*
3+
import com.mongodb.kotlin.client.MongoClient
4+
5+
// start-data-class
6+
data class Restaurant(
7+
val name: String,
8+
val borough: String,
9+
val cuisine: String
10+
)
11+
// end-data-class
12+
13+
fun main() {
14+
val uri = "<connection string>"
15+
16+
val mongoClient = MongoClient.create(uri)
17+
val database = mongoClient.getDatabase("sample_restaurants")
18+
val collection = database.getCollection<Restaurant>("restaurants")
19+
20+
// start-bulk-insert-one
21+
val blueMoon = InsertOneModel(Restaurant("Blue Moon Grill", "Brooklyn", "American"))
22+
// end-bulk-insert-one
23+
24+
// start-bulk-update-one
25+
val updateOneFilter = Filters.eq(Restaurant::name.name, "White Horse Tavern")
26+
val updateOneDoc = Updates.set(Restaurant::borough.name, "Queens")
27+
val tavernUpdate = UpdateOneModel<Restaurant>(updateOneFilter, updateOneDoc)
28+
// end-bulk-update-one
29+
30+
// start-bulk-update-many
31+
val updateManyFilter = Filters.eq(Restaurant::name.name, "Wendy's")
32+
val updateManyDoc = Updates.set(Restaurant::cuisine.name, "Fast food")
33+
val wendysUpdate = UpdateManyModel<Restaurant>(updateManyFilter, updateManyDoc)
34+
// end-bulk-update-many
35+
36+
// start-bulk-replace-one
37+
val replaceFilter = Filters.eq(Restaurant::name.name, "Cooper Town Diner")
38+
val replaceDoc = Restaurant("Smith Town Diner", "Brooklyn", "American")
39+
val replacement = ReplaceOneModel(replaceFilter, replaceDoc)
40+
// end-bulk-replace-one
41+
42+
// start-bulk-delete-one
43+
val deleteOne = DeleteOneModel<Restaurant>(Filters.eq(
44+
Restaurant::name.name,
45+
"Morris Park Bake Shop"
46+
))
47+
// end-bulk-delete-one
48+
49+
// start-bulk-delete-many
50+
val deleteMany = DeleteManyModel<Restaurant>(Filters.eq(
51+
Restaurant::cuisine.name,
52+
"Experimental"
53+
))
54+
// end-bulk-delete-many
55+
56+
// start-bulk-write-mixed
57+
val insertOneMdl = InsertOneModel(Restaurant("Red's Pizza", "Brooklyn", "Pizzeria"))
58+
val updateOneMdl = UpdateOneModel<Restaurant>(
59+
Filters.eq(Restaurant::name.name, "Moonlit Tavern"),
60+
Updates.set(Restaurant::borough.name, "Queens")
61+
)
62+
val deleteManyMdl = DeleteManyModel<Restaurant>(
63+
Filters.eq(Restaurant::name.name, "Crepe")
64+
)
65+
66+
val bulkResult = collection.bulkWrite(
67+
listOf(insertOneMdl, updateOneMdl, deleteManyMdl)
68+
)
69+
70+
println(bulkResult)
71+
// end-bulk-write-mixed
72+
73+
val bulkOperations = listOf(insertOneMdl, updateOneMdl, deleteManyMdl)
74+
75+
// start-bulk-write-unordered
76+
val opts = BulkWriteOptions().ordered(false)
77+
collection.bulkWrite(bulkOperations, opts)
78+
// end-bulk-write-unordered
79+
80+
}
81+

source/indexes/atlas-search-index.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ each of the preceding methods.
4747
Create a Search Index
4848
---------------------
4949

50-
You can use the `createSearchIndex() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/create-search-index.html>`__
51-
and the `createSearchIndexes() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/create-search-indexes.html>`__
50+
You can use the `createSearchIndex() <{+api+}/com.mongodb.kotlin.client/-mongo-collection/create-search-index.html>`__
51+
and the `createSearchIndexes() <{+api+}/com.mongodb.kotlin.client/-mongo-collection/create-search-indexes.html>`__
5252
methods to create one or more Atlas Search indexes.
5353

5454
The following code example shows how to create a single index:
@@ -77,7 +77,7 @@ List Search Indexes
7777
-------------------
7878

7979
You can use the
80-
`listSearchIndexes() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/list-search-indexes.html>`__
80+
`listSearchIndexes() <{+api+}/com.mongodb.kotlin.client/-mongo-collection/list-search-indexes.html>`__
8181
method to return all Atlas Search indexes in a collection.
8282

8383
The following code example shows how to print a list of the search indexes in
@@ -95,7 +95,7 @@ Update a Search Index
9595
---------------------
9696

9797
You can use the
98-
`updateSearchIndex() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/update-search-index.html>`__
98+
`updateSearchIndex() <{+api+}/com.mongodb.kotlin.client/-mongo-collection/update-search-index.html>`__
9999
method to update an Atlas Search index.
100100

101101
The following code shows how to update a search index:
@@ -112,7 +112,7 @@ Delete a Search Index
112112
---------------------
113113

114114
You can use the
115-
`dropSearchIndex() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/drop-search-index.html>`__
115+
`dropSearchIndex() <{+api+}/com.mongodb.kotlin.client/-mongo-collection/drop-search-index.html>`__
116116
method to delete an Atlas Search index.
117117

118118
The following code shows how to delete a search index from a collection:

source/indexes/compound-index.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,6 @@ API Documentation
9393
To learn more about any of the methods discussed in this guide, see the following API
9494
documentation:
9595

96-
- `find() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/find.html>`__
97-
- `filter() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-find-iterable/filter.html>`__
98-
- `sort() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-find-iterable/sort.html>`__
96+
- `find() <{+api+}/com.mongodb.kotlin.client/-mongo-collection/find.html>`__
97+
- `filter() <{+api+}/com.mongodb.kotlin.client/-find-iterable/filter.html>`__
98+
- `sort() <{+api+}/com.mongodb.kotlin.client/-find-iterable/sort.html>`__

source/indexes/single-field-index.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@ API Documentation
9191
To learn more about any of the methods discussed in this guide, see the following API
9292
documentation:
9393

94-
- `find() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/find.html>`__
95-
- `filter() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-find-iterable/filter.html>`__
96-
- `sort() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-find-iterable/sort.html>`__
94+
- `find() <{+api+}/com.mongodb.kotlin.client/-mongo-collection/find.html>`__
95+
- `filter() <{+api+}/com.mongodb.kotlin.client/-find-iterable/filter.html>`__
96+
- `sort() <{+api+}/com.mongodb.kotlin.client/-find-iterable/sort.html>`__

source/read/count.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,5 +201,5 @@ API Documentation
201201
To learn more about any of the methods or types discussed in this
202202
guide, see the following API documentation:
203203

204-
- `countDocuments() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/count-documents.html>`__
205-
- `estimatedDocumentCount() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/estimated-document-count.html>`__
204+
- `countDocuments() <{+api+}/com.mongodb.kotlin.client/-mongo-collection/count-documents.html>`__
205+
- `estimatedDocumentCount() <{+api+}/com.mongodb.kotlin.client/-mongo-collection/estimated-document-count.html>`__

source/read/project.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,5 @@ API Documentation
123123
To learn more about any of the methods or types discussed in this
124124
guide, see the following API Documentation:
125125

126-
- `find() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/find.html>`__
127-
- `projection() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-find-iterable/projection.html>`__
126+
- `find() <{+api+}/com.mongodb.kotlin.client/-mongo-collection/find.html>`__
127+
- `projection() <{+api+}/com.mongodb.kotlin.client/-find-iterable/projection.html>`__

source/read/retrieve.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ number of documents returned by the query to ``10`` and set a maximum execution
151151
:copyable:
152152
:dedent:
153153

154-
For a full list of methods that modify the behavior of ``find()``, see the `API documentation <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-find-iterable/index.html>`__
154+
For a full list of methods that modify the behavior of ``find()``, see the `API documentation <{+api+}/com.mongodb.kotlin.client/-find-iterable/index.html>`__
155155
for the ``FindIterable`` class.
156156

157157
Additional Information
@@ -168,5 +168,5 @@ API Documentation
168168
To learn more about any of the methods or types discussed in this guide, see the following
169169
API documentation:
170170

171-
- `find() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/find.html>`__
172-
- `FindIterable <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-find-iterable/index.html>`__
171+
- `find() <{+api+}/com.mongodb.kotlin.client/-mongo-collection/find.html>`__
172+
- `FindIterable <{+api+}/com.mongodb.kotlin.client/-find-iterable/index.html>`__

0 commit comments

Comments
 (0)