Navigation

MongoDB Scala Driver

This is the officially supported Scala driver for MongoDB.

It's a modern idiomatic Scala driver with asynchronous and non-blocking IO.

The recommended way to get started using the driver in your project is with a dependency management system like sbt or maven. See the Installation Guide for more information.

To connect to a MongoDB Atlas cluster, use the Atlas connection string for your cluster:

import org.mongodb.scala._
// ...
val uri: String = "mongodb+srv://<username>:<password>@<cluster-address>/test?retryWrites=true&w=majority"
System.setProperty("org.mongodb.async.type", "netty")
val client: MongoClient = MongoClient(uri)
val db: MongoDatabase = client.getDatabase("test")

See our guide on Connecting for more ways to connect.

To connect to a database running locally on its default port, change the connection string to "mongodb://localhost".

To connect to a database running locally, change the connection string to "mongodb://localhost:<port>".

Your mongod instance must be running to successfully connect to your database. For information on how to start your mongod instance, see the Manage mongod Processes Server Manual Entry.

Scala Driver Version
MongoDB 4.4
MongoDB 4.2
MongoDB 4.0
MongoDB 3.6
MongoDB 3.4
MongoDB 3.2
MongoDB 3.0
MongoDB 2.6
4.2
4.1
2.9
2.8
2.7
2.6
2.5
2.4
2.3
2.2
2.1
2.0
1.2
1.1
1.0

The driver does not support older versions of MongoDB.

Scala Driver Version
Scala 2.13
Scala 2.12
Scala 2.11
4.2
4.1
2.9
2.8
2.7
2.6
2.5
2.4
2.3
2.2
2.1
2.0
1.1
1.1
1.0

For more information on how to read the compatibility tables, see our guide on MongoDB Compatibility Tables.

Give Feedback

On this page

  • Introduction
  • Installation
  • Connect to MongoDB Atlas
  • Connect to localhost
  • Compatibility