Skip to content

Commit

Permalink
fix examples for bulk
Browse files Browse the repository at this point in the history
  • Loading branch information
rustagir committed Jan 16, 2025
1 parent 55c7e32 commit 8d58a64
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
13 changes: 13 additions & 0 deletions examples/src/test/kotlin/BulkTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import com.mongodb.client.model.DeleteOneModel
import com.mongodb.client.model.Filters
import com.mongodb.client.model.InsertOneModel
import com.mongodb.client.model.ReplaceOneModel
import com.mongodb.client.model.ReplaceOptions
import com.mongodb.client.model.Sorts
import com.mongodb.client.model.UpdateOneModel
import com.mongodb.client.model.UpdateOptions
import com.mongodb.client.model.Updates
import com.mongodb.kotlin.client.coroutine.MongoClient
import config.getConfig
Expand Down Expand Up @@ -95,6 +98,11 @@ internal class BulkTest {
val insert = Person(1, "Celine Stork", location = "San Diego, CA")
val doc = ReplaceOneModel(filter, insert)
// :snippet-end:

// :snippet-start: replace-model-options
val opts = ReplaceOptions().sort(Sorts.ascending("_id"))
// :snippet-end:

// Junit test for the above code
val insertTest = collection.bulkWrite(listOf(doc))
assertTrue(insertTest.wasAcknowledged())
Expand All @@ -107,6 +115,11 @@ internal class BulkTest {
val update = Updates.inc(Person::age.name, 1)
val doc = UpdateOneModel<Person>(filter, update)
// :snippet-end:

// :snippet-start: update-model-options
val opts = UpdateOptions().sort(Sorts.ascending("_id"))
// :snippet-end:

// Junit test for the above code
val updateTest = collection.bulkWrite(listOf(doc))
assertTrue(updateTest.wasAcknowledged())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val opts = ReplaceOptions().sort(Sorts.ascending("_id"))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val opts = UpdateOptions().sort(Sorts.ascending("_id"))
4 changes: 2 additions & 2 deletions source/fundamentals/crud/write-operations/bulk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ result. You can specify a sort in a ``ReplaceOptions`` instance to apply
an order to matched documents before the driver performs the replace
operation, as shown in the following code:

.. literalinclude:: /examples/generated/ChangeTest.snippet.replace-one-options.kt
.. literalinclude:: /examples/generated/BulkTest.snippet.replace-model-options.kt
:language: kotlin

For more information about the methods and classes mentioned in this section,
Expand Down Expand Up @@ -171,7 +171,7 @@ result. You can specify a sort in an ``UpdateOptions`` instance to apply
an order to matched documents before the driver performs the update
operation, as shown in the following code:

.. literalinclude:: /examples/generated/ChangeTest.snippet.update-one-options.kt
.. literalinclude:: /examples/generated/BulkTest.snippet.update-model-options.kt
:language: kotlin

For more information about the methods and classes mentioned in this section,
Expand Down

0 comments on commit 8d58a64

Please sign in to comment.