MongoDB驱动 > MongoDB Java反应流
Java Reactive Streams是MongoDB的官方Java驱动程序,是在JVM生态系统中使用响应流的推荐驱动程序。
在项目中开始使用驱动程序的推荐方法是使用依赖项管理系统。有关 更多信息,请参见《安装指南》。
要连接到MongoDB Atlas集群,请为集群使用 Atlas连接字符串:
import com.mongodb.ConnectionString;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoDatabase;
import com.mongodb.MongoClientSettings;
// ...
ConnectionString connString = new ConnectionString(
"mongodb+srv://<username>:<password>@<cluster-address>/test?w=majority"
);
MongoClientSettings settings = MongoClientSettings.builder()
.applyConnectionString(connString)
.retryWrites(true)
.build();
MongoClient mongoClient = MongoClients.create(settings);
MongoDatabase database = mongoClient.getDatabase("test");
有关更多连接 方法,请参阅连接到MongoDB。
Java Reactive Streams驱动程序版本 | MongoDB 4.2 | MongoDB 4.0 | MongoDB 3.6 | MongoDB 3.4 | MongoDB 3.2 | MongoDB 3.0 | MongoDB 2.6 |
---|---|---|---|---|---|---|---|
1.13 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1.12 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
1.11 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
1.10 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
1.9 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
1.7 | ✓ | ✓ | ✓ | ✓ | ✓ | ||
1.6 | ✓ | ✓ | ✓ | ✓ | |||
1.5 | ✓ | ✓ | ✓ | ✓ | |||
1.3 | ✓ | ✓ | ✓ | ✓ | |||
1.2 | ✓ | ✓ | ✓ | ||||
1.1 | ✓ | ✓ | |||||
1.0 | ✓ | ✓ |
该驱动程序不支持旧版本的MongoDB。
Java Reactive Streams驱动程序版本 | Java 6 | Java 7 | Java 8 | Java 11 [ ] |
---|---|---|---|---|
1.13 | ✓ | ✓ | ✓ | ✓ |
1.12 | ✓ | ✓ | ✓ | ✓ |
1.11 | ✓ | ✓ | ✓ | ✓ |
1.10 | ✓ | ✓ | ✓ | ✓ |
1.9 | ✓ | ✓ | ✓ | ✓ |
1.7 | ✓ | ✓ | ✓ | ✓ |
1.6 | ✓ | ✓ | ✓ | ✓ |
1.5 | ✓ | ✓ | ✓ | ✓ |
1.3 | ✓ | ✓ | ✓ | ✓ |
1.2 | ✓ | ✓ | ✓ | ✓ |
1.1 | ✓ | ✓ | ✓ | ✓ |
1.0 | ✓ | ✓ | ✓ | ✓ |
[ ] | () 由于JVM向后兼容承诺,因此全部支持Java 8及更高版本。将来只会明确列出LTS版本。 |