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 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 Connecting for more ways to connect.

Compatibility

MongoDB Compatibility

The following compatibility table specifies the recommended version(s) of the Mongo Scala driver for use with a specific version of MongoDB.

The first column lists the driver version(s).

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

The driver does not support older versions of MongoDB.

Language Compatibility

The following compatibility table specifies the recommended version(s) of the Mongo Scala driver for use with a specific version of Scala.

The first column lists the driver version(s).

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