-
Notifications
You must be signed in to change notification settings - Fork 10
DOCSP-41130: bulk write operations #27
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0f02d52
DOCSP-41130: bulk write
rustagir 4ddb4d8
Merge branch 'master' of github.com:mongodb/docs-kotlin-sync into DOC…
rustagir 77d075d
DOCSP-41130
rustagir 65b18fe
add code
rustagir d9950ee
add api references
rustagir 9214dba
dedent
rustagir 5e73c26
MM PR fixes 1 + source constant edit
rustagir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side: This repeat in the URL is wierd - I would recommend copying the nested directories contents to the level up to remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into this and re-deploy the Kotlin API docs!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://jira.mongodb.org/browse/DOCSP-42238