Navigation

MongoDB Scala Driver

Introduction

This is the officially supported Scala driver for MongoDB.

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

Installation

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.

Connect to MongoDB Atlas

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.

Compatibility

MongoDB Compatibility

Scala DriverMongoDB 4.2MongoDB 4.0MongoDB 3.6MongoDB 3.4MongoDB 3.2MongoDB 3.0MongoDB 2.6
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.

Language Compatibility

Scala DriverScala 2.13Scala 2.12Scala 2.11
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

How to get help