Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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: 1 addition & 1 deletion snooty.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ mdb-server = "MongoDB Server"
stable-api = "Stable API"
api = "https://mongodb.github.io/mongo-java-driver/{+version-number+}/apidocs/mongodb-driver-kotlin-sync"
java-api = "https://mongodb.github.io/mongo-java-driver/{+version-number+}"
core-api = "{+java-api+}/apidocs/mongodb-driver-core/"
core-api = "{+java-api+}/apidocs/mongodb-driver-core"
kotlin-docs = "https://kotlinlang.org"
12 changes: 6 additions & 6 deletions source/connect/stable-api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ API Documentation
For more information about using the {+stable-api+} with {+driver-short+}, see the
following API documentation:

- `ServerApi <{+core-api+}com/mongodb/ServerApi.html>`__
- `ServerApi.Builder <{+core-api+}com/mongodb/ServerApi.Builder.html>`__
- `ServerApiVersion <{+core-api+}com/mongodb/ServerApiVersion.html>`__
- `ServerAddress <{+core-api+}com/mongodb/ServerAddress.html>`__
- `MongoClientSettings <{+core-api+}com/mongodb/MongoClientSettings.html>`__
- `MongoClientSettings.Builder <{+core-api+}com/mongodb/MongoClientSettings.Builder.html>`__
- `ServerApi <{+core-api+}/com/mongodb/ServerApi.html>`__
- `ServerApi.Builder <{+core-api+}/com/mongodb/ServerApi.Builder.html>`__
- `ServerApiVersion <{+core-api+}/com/mongodb/ServerApiVersion.html>`__
- `ServerAddress <{+core-api+}/com/mongodb/ServerAddress.html>`__
- `MongoClientSettings <{+core-api+}/com/mongodb/MongoClientSettings.html>`__
- `MongoClientSettings.Builder <{+core-api+}/com/mongodb/MongoClientSettings.Builder.html>`__
- `MongoClient <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-client/index.html>`__
- `MongoClient.create() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-client/-factory/create.html>`__
81 changes: 81 additions & 0 deletions source/includes/write/bulk.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import com.mongodb.client.model.*
import com.mongodb.client.model.Filters.*
import com.mongodb.kotlin.client.MongoClient

// start-data-class
data class Restaurant(
val name: String,
val borough: String,
val cuisine: String
)
// end-data-class

fun main() {
val uri = "<connection string>"

val mongoClient = MongoClient.create(uri)
val database = mongoClient.getDatabase("sample_restaurants")
val collection = database.getCollection<Restaurant>("restaurants")

// start-bulk-insert-one
val blueMoon = InsertOneModel(Restaurant("Blue Moon Grill", "Brooklyn", "American"))
// end-bulk-insert-one

// start-bulk-update-one
val updateOneFilter = Filters.eq(Restaurant::name.name, "White Horse Tavern")
val updateOneDoc = Updates.set(Restaurant::borough.name, "Queens")
val tavernUpdate = UpdateOneModel<Restaurant>(updateOneFilter, updateOneDoc)
// end-bulk-update-one

// start-bulk-update-many
val updateManyFilter = Filters.eq(Restaurant::name.name, "Wendy's")
val updateManyDoc = Updates.set(Restaurant::cuisine.name, "Fast food")
val wendysUpdate = UpdateManyModel<Restaurant>(updateManyFilter, updateManyDoc)
// end-bulk-update-many

// start-bulk-replace-one
val replaceFilter = Filters.eq(Restaurant::name.name, "Cooper Town Diner")
val replaceDoc = Restaurant("Smith Town Diner", "Brooklyn", "American")
val replacement = ReplaceOneModel(replaceFilter, replaceDoc)
// end-bulk-replace-one

// start-bulk-delete-one
val deleteOne = DeleteOneModel<Restaurant>(Filters.eq(
Restaurant::name.name,
"Morris Park Bake Shop"
))
// end-bulk-delete-one

// start-bulk-delete-many
val deleteMany = DeleteManyModel<Restaurant>(Filters.eq(
Restaurant::cuisine.name,
"Experimental"
))
// end-bulk-delete-many

// start-bulk-write-mixed
val insertOneMdl = InsertOneModel(Restaurant("Red's Pizza", "Brooklyn", "Pizzeria"))
val updateOneMdl = UpdateOneModel<Restaurant>(
Filters.eq(Restaurant::name.name, "Moonlit Tavern"),
Updates.set(Restaurant::borough.name, "Queens")
)
val deleteManyMdl = DeleteManyModel<Restaurant>(
Filters.eq(Restaurant::name.name, "Crepe")
)

val bulkResult = collection.bulkWrite(
listOf(insertOneMdl, updateOneMdl, deleteManyMdl)
)

println(bulkResult)
// end-bulk-write-mixed

val bulkOperations = listOf(insertOneMdl, updateOneMdl, deleteManyMdl)

// start-bulk-write-unordered
val opts = BulkWriteOptions().ordered(false)
collection.bulkWrite(bulkOperations, opts)
// end-bulk-write-unordered

}

6 changes: 3 additions & 3 deletions source/write-operations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Write Data to MongoDB
/write/insert
/write/update
/write/delete
/write/bulk-write

..
/write/replace
/write/bulk-write
/write/gridfs

Overview
Expand Down Expand Up @@ -183,5 +183,5 @@ single bulk operation:
:copyable:
:dedent:

.. To learn more about the ``bulk_write()`` method, see the
.. :ref:`Bulk Write <kotlin-sync-bulk-write>` guide.
To learn more about the ``bulkWrite()`` method, see the
:ref:`Bulk Write <kotlin-sync-bulk-write>` guide.
Loading
Loading