MongoDB驱动 > Scala驱动程序
这是MongoDB的官方受支持的Scala驱动程序。
它是具有异步和非阻塞IO的现代惯用Scala驱动程序。
在项目中开始使用驱动程序的推荐方法是使用依赖管理系统,例如sbt
或maven
。有关
更多信息,请参见《
安装指南》。
要连接到MongoDB Atlas集群,请为集群使用 Atlas连接字符串:
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")
有关更多连接方式,请参见我们的连接指南。
Scala驱动程序 | MongoDB 4.2 | MongoDB 4.0 | MongoDB 3.6 | MongoDB 3.4 | MongoDB 3.2 | MongoDB 3.0 | MongoDB 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 | ✓ | ✓ |
该驱动程序不支持旧版本的MongoDB。
Scala驱动程序 | 斯卡拉2.13 | 斯卡拉2.12 | 斯卡拉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 | ✓ |