Skip to content
Open
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
13 changes: 13 additions & 0 deletions code-examples/scala/stable-api/basic.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import org.mongodb.scala._

// Replace the placeholders in the connection string uri with your credentials
val uri: String = "mongodb+srv://<user>:<password>@<cluster-url>?retryWrites=true&w=majority"

// Create Settings with API version
val settings: MongoClientSettings = MongoClientSettings.builder()
.applyConnectionString(new ConnectionString(uri))
.serverApi(ServerApi.builder().version(ServerApiVersion.V1).build())
.build()

// Create a client with specified settings
val mongoClient: MongoClient = MongoClient(settings)
18 changes: 18 additions & 0 deletions code-examples/scala/stable-api/options.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Stable API - with options
// begin serverApiVersion

import org.mongodb.scala._

// Replace the placeholders in the connection string uri with your credentials
val uri: String = "mongodb+srv://<user>:<password>@<cluster-url>?retryWrites=true&w=majority"

/* Create a client with options to specify Stable API Version 1, return
errors for commands outside of the API version, and raise exceptions
for deprecated commands */
val settings: MongoClientSettings = MongoClientSettings.builder()
.applyConnectionString(new ConnectionString(uri))
.serverApi(new ServerApi(ServerApiVersion.V1, true, true))
.build()

val client: MongoClient = MongoClient(settings)
// end serverApiVersion