MongoDB クライアントの利用
MongoDBは広く使われているNoSQLデータベースとして知られています。
このガイドでは、RESTサービスでMongoDBデータベースを使用する方法を見ていきます。
前提条件
このガイドを完成させるには、以下が必要です:
-
約15分
-
IDE
-
JDK 11+ がインストールされ、
JAVA_HOME
が適切に設定されていること -
Apache Maven 3.8.1+
-
使用したい場合、 Quarkus CLI
-
ネイティブ実行可能ファイルをビルドしたい場合、MandrelまたはGraalVM(あるいはネイティブなコンテナビルドを使用する場合はDocker)をインストールし、 適切に設定していること
-
MongoDBがインストールされているか、Dockerがインストールされている
アーキテクチャ
このガイドで構築されるアプリケーションは非常にシンプルです: ユーザーはフォームを使用してリストに要素を追加することができ、リストは更新されます。
ブラウザとサーバー間の情報はすべてJSON形式になっています。
要素はMongoDBに格納されています。
ソリューション
次の節で紹介する手順に沿って、ステップを踏んでアプリを作成することをお勧めします。ただし、完成した例にそのまま進んでも構いません。
Gitレポジトリをクローンするか git clone https://github.com/quarkusio/quarkus-quickstarts.git
、 アーカイブ をダウンロードします。
ソリューションは mongodb-quickstart
ディレクトリ にあります。
Mavenプロジェクトの作成
まず、新しいプロジェクトが必要です。以下のコマンドで新規プロジェクトを作成します。
このコマンドは、RESTEasy Reactive JacksonとMongoDB ClientエクステンションをインポートするMaven構造を生成します。その後、 quarkus-mongodb-client
エクステンションがビルドファイルに追加されます。
すでにQuarkusプロジェクトが設定されている場合は、プロジェクトのベースディレクトリーで以下のコマンドを実行することで、プロジェクトに mongodb-client
エクステンションを追加することができます。
quarkus extension add 'mongodb-client'
./mvnw quarkus:add-extension -Dextensions="mongodb-client"
./gradlew addExtension --extensions="mongodb-client"
これにより、 pom.xml
に以下が追加されます:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-mongodb-client</artifactId>
</dependency>
implementation("io.quarkus:quarkus-mongodb-client")
初めてのJSON RESTサービスの作成
この例では、果物のリストを管理するアプリケーションを作成します。
まず、以下のように Fruit
Bean を作成してみましょう。
package org.acme.mongodb;
import java.util.Objects;
public class Fruit {
private String name;
private String description;
private String id;
public Fruit() {
}
public Fruit(String name, String description) {
this.name = name;
this.description = description;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Fruit)) {
return false;
}
Fruit other = (Fruit) obj;
return Objects.equals(other.name, this.name);
}
@Override
public int hashCode() {
return Objects.hash(this.name);
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
}
派手なことは何もありません。注意すべき重要なことは、デフォルトのコンストラクタを持つことはJSONシリアライズレイヤーで必須であるということです。
今、私たちのアプリケーションのビジネス層となる org.acme.mongodb.FruitService
を作成し、mongoDB データベースからフルーツを保存/ロードします。
package org.acme.mongodb;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import org.bson.Document;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
@ApplicationScoped
public class FruitService {
@Inject MongoClient mongoClient;
public List<Fruit> list(){
List<Fruit> list = new ArrayList<>();
MongoCursor<Document> cursor = getCollection().find().iterator();
try {
while (cursor.hasNext()) {
Document document = cursor.next();
Fruit fruit = new Fruit();
fruit.setName(document.getString("name"));
fruit.setDescription(document.getString("description"));
list.add(fruit);
}
} finally {
cursor.close();
}
return list;
}
public void add(Fruit fruit){
Document document = new Document()
.append("name", fruit.getName())
.append("description", fruit.getDescription());
getCollection().insertOne(document);
}
private MongoCollection getCollection(){
return mongoClient.getDatabase("fruit").getCollection("fruit");
}
}
では、次のように org.acme.mongodb.FruitResource
クラスを作成します。
@Path("/fruits")
public class FruitResource {
@Inject FruitService fruitService;
@GET
public List<Fruit> list() {
return fruitService.list();
}
@POST
public List<Fruit> add(Fruit fruit) {
fruitService.add(fruit);
return list();
}
}
The implementation is pretty straightforward, and you just need to define your endpoints using the JAX-RS annotations and use the FruitService
to list/add new fruits.
MongoDBデータベースの設定
The main property to configure is the URL to access to MongoDB. Almost all configuration can be included in the connection URI, so we advise you to do so. You can find more information in the MongoDB documentation: https://docs.mongodb.com/manual/reference/connection-string/
設定のサンプルは以下のようになります。
# configure the mongoDB client for a replica set of two nodes
quarkus.mongodb.connection-string = mongodb://mongo1:27017,mongo2:27017
この例では、ローカルホスト上で実行されている単一のインスタンスを使用しています。
# configure the mongoDB client for a single instance on localhost
quarkus.mongodb.connection-string = mongodb://localhost:27017
その他の設定プロパティーが必要な場合は、このガイドの最後に完全なリストがあります。
By default, Quarkus will restrict the use of JNDI within an application, as a precaution to try and mitigate any future vulnerabilities similar to Log4Shell. Because the mongo+srv protocol often used to connect to MongoDB requires JNDI, this protection is automatically disabled when using the MongoDB client extension.
|
開発サービス(コンフィグレーション・フリー・データベース)
Quarkus supports a feature called Dev Services that allows you to create various datasources without any config. In the case of MongoDB this support extends to the default MongoDB connection. What that means practically, is that if you have not configured quarkus.mongodb.connection-string
Quarkus will automatically start a MongoDB container when running tests or dev mode, and automatically configure the connection.
本番環境のアプリケーションを実行する場合、MongoDBの接続は通常通りに設定する必要があります。本番環境のデータベースの設定を application.properties
に含めてDev Servicesを継続して使用する場合は、 %prod.
プロファイルを使用してMongoDBの設定を定義することをお勧めします。
ビルド時に固定される設定プロパティ - それ以外の設定プロパティは実行時に上書き可能
タイプ |
デフォルト |
|
---|---|---|
If DevServices has been explicitly enabled or disabled. DevServices is generally enabled by default, unless there is an existing configuration present. When DevServices is enabled Quarkus will attempt to automatically configure and start a database when running in Dev or Test mode. Environment variable: |
boolean |
|
The container image name to use, for container based DevServices providers. Environment variable: |
string |
|
Optional fixed port the dev service will listen to. If not defined, the port will be chosen randomly. Environment variable: |
int |
|
Generic properties that are added to the connection URL. Environment variable: |
|
複数のMongoDBクライアント
MongoDBでは、複数のクライアントを設定することができます。複数のクライアントを使っても、単一のクライアントを持つのと同じように動作します。
quarkus.mongodb.connection-string = mongodb://login:pass@mongo1:27017/database
quarkus.mongodb.users.connection-string = mongodb://mongo2:27017/userdb
quarkus.mongodb.inventory.connection-string = mongodb://mongo3:27017/invdb,mongo4:27017/invdb
キーに余分なビットがあることに注意してください ( users
と inventory
のセグメント)。構文は以下の通りです。 quarkus.mongodb.[optional name.][mongo connection property]
.名前を省略すると、デフォルトのクライアントを設定します。
The use of multiple MongoDB clients enables multi-tenancy for MongoDB by allowing to connect to multiple MongoDB clusters. + If you want to connect to multiple databases inside the same cluster, multiple clients are not necessary as a single client is able to access all databases in the same cluster (as a JDBC connection is able to access to multiple schemas inside the same database). |
名前付きMongoクライアントの注入
複数のクライアントを使用する場合、各 MongoClient
は、 io.quarkus.mongodb.MongoClientName
の修飾子を使用して注入するクライアントを選択できます。上記のプロパティーを使用して、以下のように3つの異なるクライアントを設定し、それぞれに注入することもできます。
@Inject
MongoClient defaultMongoClient;
@Inject
@MongoClientName("users")
MongoClient mongoClient1;
@Inject
@MongoClientName("inventory")
ReactiveMongoClient mongoClient2;
MongoDB データベースの実行
デフォルトでは、 MongoClient
はポート 27017 (デフォルトの MongoDB ポート) でローカルの MongoDB データベースにアクセスするように設定されています。このポートで実行されているローカルのデータベースがある場合は、他に何もする必要はありません!
Dockerを使ってMongoDBデータベースを起動したい場合は、以下のコマンドで起動することができます。
docker run -ti --rm -p 27017:27017 mongo:4.0
Dev Servicesを使用している場合は、手動でコンテナを起動する必要はありません。 |
フロントエンドの作成
ここで、 FruitResource
と対話するための簡単なウェブページを追加してみましょう。Quarkusは、 META-INF/resources
ディレクトリーの下にある静的なリソースを自動的に提供します。 src/main/resources/META-INF/resources
ディレクトリーに、この fruits.htmlファイルの内容を含む fruits.html
ファイルを追加します。
これで、REST サービスと対話できるようになりました。
-
Quarkusを起動します。
CLIquarkus dev
Maven./mvnw quarkus:dev
Gradle./gradlew --console=plain quarkusDev
-
http://localhost:8080/fruits.html
をブラウザで開く -
フォームを使って新しいフルーツをリストに追加します。 :!devtools-wrapped:
リアクティブな MongoDB クライアント
リアクティブなMongoDBクライアントがQuarkusに含まれています。これを使うのは、古典的なMongoDBクライアントを使うのと同じくらい簡単です。先ほどの例を以下のように書き換えて使うことができます。
非推奨
|
Mutiny
MongoDBのリアクティブ・クライアントは、Mutinyのリアクティブ・タイプを使用しています。Mutinyに慣れていない方は、 Mutiny - an intuitive reactive programming libraryをご覧ください。 |
package org.acme.mongodb;
import io.quarkus.mongodb.reactive.ReactiveMongoClient;
import io.quarkus.mongodb.reactive.ReactiveMongoCollection;
import io.smallrye.mutiny.Uni;
import org.bson.Document;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.util.List;
@ApplicationScoped
public class ReactiveFruitService {
@Inject
ReactiveMongoClient mongoClient;
public Uni<List<Fruit>> list() {
return getCollection().find()
.map(doc -> {
Fruit fruit = new Fruit();
fruit.setName(doc.getString("name"));
fruit.setDescription(doc.getString("description"));
return fruit;
}).collect().asList();
}
public Uni<Void> add(Fruit fruit) {
Document document = new Document()
.append("name", fruit.getName())
.append("description", fruit.getDescription());
return getCollection().insertOne(document)
.onItem().ignore().andContinueWithNull();
}
private ReactiveMongoCollection<Document> getCollection() {
return mongoClient.getDatabase("fruit").getCollection("fruit");
}
}
package org.acme.mongodb;
import io.smallrye.mutiny.Uni;
import java.util.List;
import javax.inject.Inject;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.core.MediaType;
@Path("/reactive_fruits")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class ReactiveFruitResource {
@Inject
ReactiveFruitService fruitService;
@GET
public Uni<List<Fruit>> list() {
return fruitService.list();
}
@POST
public Uni<List<Fruit>> add(Fruit fruit) {
return fruitService.add(fruit)
.onItem().ignore().andSwitchTo(this::list);
}
}
BSONコーデックを使ってMongoDBクライアントの利用をシンプルにする
Bson Codec
を使用することで、MongoDB クライアントは自動的に MongoDB Document
への/からのドメインオブジェクトの変換の世話をします。
まず、Bson Codec
を作成する必要があります。これは、エンティティーを MongoDB Document
に変換する方法を Bson に伝えます。ここでは CollectibleCodec
を使用しています。私たちのオブジェクトはデータベースから取得可能なので (MongoDB の識別子を持っています)、そうでなければ Codec
を使用します。詳細はコーデックのドキュメントを参照ください: https://mongodb.github.io/mongo-java-driver/3.10/bson/codecs 。
package org.acme.mongodb.codec;
import com.mongodb.MongoClientSettings;
import org.acme.mongodb.Fruit;
import org.bson.Document;
import org.bson.BsonWriter;
import org.bson.BsonValue;
import org.bson.BsonReader;
import org.bson.BsonString;
import org.bson.codecs.Codec;
import org.bson.codecs.CollectibleCodec;
import org.bson.codecs.DecoderContext;
import org.bson.codecs.EncoderContext;
import java.util.UUID;
public class FruitCodec implements CollectibleCodec<Fruit> {
private final Codec<Document> documentCodec;
public FruitCodec() {
this.documentCodec = MongoClientSettings.getDefaultCodecRegistry().get(Document.class);
}
@Override
public void encode(BsonWriter writer, Fruit fruit, EncoderContext encoderContext) {
Document doc = new Document();
doc.put("name", fruit.getName());
doc.put("description", fruit.getDescription());
documentCodec.encode(writer, doc, encoderContext);
}
@Override
public Class<Fruit> getEncoderClass() {
return Fruit.class;
}
@Override
public Fruit generateIdIfAbsentFromDocument(Fruit document) {
if (!documentHasId(document)) {
document.setId(UUID.randomUUID().toString());
}
return document;
}
@Override
public boolean documentHasId(Fruit document) {
return document.getId() != null;
}
@Override
public BsonValue getDocumentId(Fruit document) {
return new BsonString(document.getId());
}
@Override
public Fruit decode(BsonReader reader, DecoderContext decoderContext) {
Document document = documentCodec.decode(reader, decoderContext);
Fruit fruit = new Fruit();
if (document.getString("id") != null) {
fruit.setId(document.getString("id"));
}
fruit.setName(document.getString("name"));
fruit.setDescription(document.getString("description"));
return fruit;
}
}
そして、この Codec
を Fruit
クラスにリンクさせるための CodecProvider
を作成する必要があります。
package org.acme.mongodb.codec;
import org.acme.mongodb.Fruit;
import org.bson.codecs.Codec;
import org.bson.codecs.configuration.CodecProvider;
import org.bson.codecs.configuration.CodecRegistry;
public class FruitCodecProvider implements CodecProvider {
@Override
public <T> Codec<T> get(Class<T> clazz, CodecRegistry registry) {
if (clazz.equals(Fruit.class)) {
return (Codec<T>) new FruitCodec();
}
return null;
}
}
Quarkusは、 CodecProvider
を @Singleton
スコープのCDIビーンとして登録する作業を行います。
最後に、データベースから MongoCollection
を取得するとき、 Document
の代わりに Fruit
クラスを直接使用することができます。コーデックは自動的に Document
を Fruit
クラスにマッピングします。
これが、 MongoCollection
を FruitCodec
と使用する例です。
package org.acme.mongodb;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
@ApplicationScoped
public class CodecFruitService {
@Inject MongoClient mongoClient;
public List<Fruit> list(){
List<Fruit> list = new ArrayList<>();
MongoCursor<Fruit> cursor = getCollection().find().iterator();
try {
while (cursor.hasNext()) {
list.add(cursor.next());
}
} finally {
cursor.close();
}
return list;
}
public void add(Fruit fruit){
getCollection().insertOne(fruit);
}
private MongoCollection<Fruit> getCollection(){
return mongoClient.getDatabase("fruit").getCollection("fruit", Fruit.class);
}
}
POJOコーデック
The POJO Codec provides a set of annotations that enable the customization of the way a POJO is mapped to a MongoDB collection and this codec is initialized automatically by Quarkus
このアノテーションのひとつに @BsonDiscriminator
アノテーションがありますが、これは、ドキュメントの中にデリミタフィールドを追加することで、複数の Java 型をひとつの MongoDB コレクションに保存できるようにするものです。抽象的な型やインターフェイスを扱うときに便利です。
Quarkusは、 @BsonDiscriminator
でアノテーションされたすべてのクラスをPOJOコーデックで自動的に登録します。
POJO Codecでは、 PropertyCodecProvider
によるジェネリックサポートが強化されています。Quarkusでは、POJO Codecで PropertyCodecProvider
を使用すると自動的に登録されます(これらのクラスは自動的に @Singleton
スコープのCDI Beanになります)。ネイティブ実行可能ファイルをビルドしてジェネリック型を使用する場合、リフレクションのために型の引数を登録する必要があるかもしれません。
PanacheでMongoDBをシンプルにする
MongoDB with Panacheエクステンションは、 Hibernate ORM with Panacheにあるようなアクティブレコードスタイルのエンティティ(およびリポジトリ)を提供することで、MongoDBの利用を促進し、Quarkusでエンティティを簡単に楽しく書けるようにすることに重点を置いています。
接続のヘルスチェック
quarkus-smallrye-health
エクステンションを使用している場合、 quarkus-mongodb-client
はクラスターへの接続を検証するためのReadinessヘルスチェックを自動的に追加します。
そのため、アプリケーションの /q/health/ready
エンドポイントにアクセスすると、接続の検証状況に関する情報が表示されます。
この動作は、 application.properties
で quarkus.mongodb.health.enabled
プロパティーを false
に設定することで無効にできます。
メトリクス
quarkus-micrometer
または quarkus-smallrye-metrics
エクステンションを使用している場合、 quarkus-mongodb-client
は接続プールに関するメトリクスを提供することができます。この動作を有効にするには、まず application.properties
の quarkus.mongodb.metrics.enabled
プロパティーを true
に設定する必要があります。
そのため、アプリケーションの /q/metrics
エンドポイントにアクセスすると、接続プールの状況に関する情報が表示されます。SmallRye Metricsを使用すると、接続プールのメトリクスは vendor
スコープの配下で利用可能になっています。
トレース
quarkus-smallrye-opentracing
エクステンションを使用している場合、 quarkus-mongodb-client
は実行されたコマンドについてのトレースを登録することができます。この動作を有効にするには、まず application.properties
の quarkus.mongodb.tracing.enabled
プロパティーを true
に設定する必要があり、pom.xmlに`io.opentracing.contrib:opentracing-mongo-common`の依存関係を追加する必要があります (詳細は OpenTracing - MongoDB clientセクションをご覧ください)。
OpenTracingの設定方法やJaegerトレーサーの使用方法については、 OpenTracingガイドをお読みください。
テストヘルパー
ユニットテスト用にMongoDBデータベースを起動するために、Quarkusは Flapdoodle embedded MongoDBに依存する2つの QuarkusTestResourceLifecycleManager
を提供しています。
-
io.quarkus.test.mongodb.MongoTestResource
は、ポート27017に単一のインスタンスを起動します。 -
io.quarkus.test.mongodb.MongoReplicaSetTestResource
は、ポート27017とポート27018にある2つのインスタンスでレプリカセットを開始します。
これらを使用するには、 io.quarkus:quarkus-test-mongodb
の依存関係を pom.xml に追加する必要があります。
QuarkusTestResourceLifecycleManager
の使い方については、 Quarkusのテストリソースをご覧ください。
レガシークライアント
デフォルトではレガシーな MongoDB クライアントは含まれていません。今では引退した MongoDB Java API (DB, DBCollection, … ) と com.mongodb.MongoClient
が含まれていますが、今では com.mongodb.client.MongoClient
に取って代わられています。
レガシーAPIを使用したい場合は、次の依存関係をビルドファイルに追加する必要があります。
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-legacy</artifactId>
</dependency>
implementation("org.mongodb:mongodb-driver-legacy")
ネイティブ実行可能ファイルの構築
MongoDBクライアントをネイティブ実行可能ファイルで使うことができます。
SSL/TLS 暗号化を使用したい場合は、これらのプロパティを application.properties
に追加する必要があります。
quarkus.mongodb.tls=true
quarkus.mongodb.tls-insecure=true # only if TLS certificate cannot be validated
その後、通常のコマンドでネイティブ実行可能ファイルをビルドすることができます。
quarkus build --native
+
./mvnw package -Dnative
+
./gradlew build -Dquarkus.package.type=native
実行は ./target/mongodb-quickstart-1.0-SNAPSHOT-runner
を実行するだけで簡単です。
その後、ブラウザで http://localhost:8080/fruits.html
を開き、アプリケーションを使用します。
現在、Quarkusはネイティブモードでの Client-Side Field Level Encryptionをサポートしていません。 |
アプリケーションをネイティブモードで実行した際に、以下のようなエラーが発生した場合があります。+ |
mongo+srv://のURLの使用
mongo+srv://
url は、JVM モードではサポートされます。しかし、ネイティブモードでは、MongoDB クライアントが提供するデフォルトの DNS リゾルバは JNDI を使っているので動作しません。
mongo+srv://
をネイティブモードで使用する必要がある場合は、代替の DNS リゾルバを設定することができます。この機能は *実験的な*もので、JVMアプリケーションとネイティブアプリケーションの間に違いが生じる可能性があります。
代替のDNSリゾルバを有効にするには
quarkus.mongodb.native.dns.use-vertx-dns-resolver=true
プロパティ名で示されているように、Vert.xを使用してDNSレコードを取得します。デフォルトでは、 /etc/resolv.conf
から最初の nameserver
を読み取ろうとします。このファイルが存在する場合は、そのファイルを使用します。また、DNS サーバーを設定することもできます。
quarkus.mongodb.native.dns.use-vertx-dns-resolver=true
quarkus.mongodb.native.dns.server-host=10.0.0.1
quarkus.mongodb.native.dns.server-port=53 # 53 is the default port
また、ルックアップのタイムアウトは、以下の方法で設定できます。
quarkus.mongodb.native.dns.use-vertx-dns-resolver=true
quarkus.mongodb.native.dns.lookup-timeout=10s # the default is 5s
設定リファレンス
ビルド時に固定される設定プロパティ - それ以外の設定プロパティは実行時に上書き可能
タイプ |
デフォルト |
|
---|---|---|
Whether a health check is published in case the smallrye-health extension is present. Environment variable: |
boolean |
|
Whether metrics are published in case a metrics extension is present. Environment variable: |
boolean |
|
Whether tracing spans of driver commands are sent in case the smallrye-opentracing extension is present. Environment variable: |
boolean |
|
If set to true, the default clients will always be created even if there are no injection points that use them Environment variable: |
boolean |
|
If DevServices has been explicitly enabled or disabled. DevServices is generally enabled by default, unless there is an existing configuration present. When DevServices is enabled Quarkus will attempt to automatically configure and start a database when running in Dev or Test mode. Environment variable: |
boolean |
|
The container image name to use, for container based DevServices providers. Environment variable: |
string |
|
Optional fixed port the dev service will listen to. If not defined, the port will be chosen randomly. Environment variable: |
int |
|
Configures the connection string. The format is: Environment variable: |
string |
|
Configures the MongoDB server addressed (one if single mode). The addresses are passed as Environment variable: |
list of string |
|
Configure the database name. Environment variable: |
string |
|
Configures the application name. Environment variable: |
string |
|
Configures the maximum number of connections in the connection pool. Environment variable: |
int |
|
Configures the minimum number of connections in the connection pool. Environment variable: |
int |
|
Maximum idle time of a pooled connection. A connection that exceeds this limit will be closed. Environment variable: |
||
Maximum lifetime of a pooled connection. A connection that exceeds this limit will be closed. Environment variable: |
||
Configures the time period between runs of the maintenance job. Environment variable: |
||
Configures period of time to wait before running the first maintenance job on the connection pool. Environment variable: |
||
How long a connection can take to be opened before timing out. Environment variable: |
||
How long a socket read can take before timing out. Environment variable: |
||
If connecting with TLS, this option enables insecure TLS connections. Environment variable: |
boolean |
|
Whether to connect using TLS. Environment variable: |
boolean |
|
Implies that the hosts given are a seed list, and the driver will attempt to find all members of the set. Environment variable: |
string |
|
How long the driver will wait for server selection to succeed before throwing an exception. Environment variable: |
||
When choosing among multiple MongoDB servers to send a request, the driver will only send that request to a server whose ping time is less than or equal to the server with the fastest ping time plus the local threshold. Environment variable: |
||
The frequency that the driver will attempt to determine the current state of each server in the cluster. Environment variable: |
||
Configures the read concern. Supported values are: Environment variable: |
string |
|
Configures the read preferences. Supported values are: Environment variable: |
string |
|
The database used during the readiness health checks Environment variable: |
string |
|
The default DNS resolver used to handle Environment variable: |
boolean |
|
If Environment variable: |
string |
|
If Environment variable: |
int |
|
If Environment variable: |
|
|
If Environment variable: |
boolean |
|
Generic properties that are added to the connection URL. Environment variable: |
|
|
Configures the connection string. The format is: Environment variable: |
string |
|
Configures the MongoDB server addressed (one if single mode). The addresses are passed as Environment variable: |
list of string |
|
Configure the database name. Environment variable: |
string |
|
Configures the application name. Environment variable: |
string |
|
Configures the maximum number of connections in the connection pool. Environment variable: |
int |
|
Configures the minimum number of connections in the connection pool. Environment variable: |
int |
|
Maximum idle time of a pooled connection. A connection that exceeds this limit will be closed. Environment variable: |
||
Maximum lifetime of a pooled connection. A connection that exceeds this limit will be closed. Environment variable: |
||
Configures the time period between runs of the maintenance job. Environment variable: |
||
Configures period of time to wait before running the first maintenance job on the connection pool. Environment variable: |
||
How long a connection can take to be opened before timing out. Environment variable: |
||
How long a socket read can take before timing out. Environment variable: |
||
If connecting with TLS, this option enables insecure TLS connections. Environment variable: |
boolean |
|
Whether to connect using TLS. Environment variable: |
boolean |
|
Implies that the hosts given are a seed list, and the driver will attempt to find all members of the set. Environment variable: |
string |
|
How long the driver will wait for server selection to succeed before throwing an exception. Environment variable: |
||
When choosing among multiple MongoDB servers to send a request, the driver will only send that request to a server whose ping time is less than or equal to the server with the fastest ping time plus the local threshold. Environment variable: |
||
The frequency that the driver will attempt to determine the current state of each server in the cluster. Environment variable: |
||
Configures the read concern. Supported values are: Environment variable: |
string |
|
Configures the read preferences. Supported values are: Environment variable: |
string |
|
The database used during the readiness health checks Environment variable: |
string |
|
タイプ |
デフォルト |
|
Configures the safety. If set to Environment variable: |
boolean |
|
Configures the journal writing aspect. If set to Environment variable: |
boolean |
|
When set, the driver adds Environment variable: |
string |
|
If set to Environment variable: |
boolean |
|
When set, the driver adds Environment variable: |
||
Configures the safety. If set to Environment variable: |
boolean |
|
Configures the journal writing aspect. If set to Environment variable: |
boolean |
|
When set, the driver adds Environment variable: |
string |
|
If set to Environment variable: |
boolean |
|
When set, the driver adds Environment variable: |
||
タイプ |
デフォルト |
|
Configures the username. Environment variable: |
string |
|
Configures the password. Environment variable: |
string |
|
Configures the authentication mechanism to use if a credential was supplied. The default is unspecified, in which case the client will pick the most secure mechanism available based on the sever version. For the GSSAPI and MONGODB-X509 mechanisms, no password is accepted, only the username. Supported values: null or Environment variable: |
string |
|
Configures the source of the authentication credentials. This is typically the database that the credentials have been created. The value defaults to the database specified in the path portion of the connection string or in the 'database' configuration property. If the database is specified in neither place, the default value is Environment variable: |
string |
|
Allows passing authentication mechanism properties. Environment variable: |
|
|
Configures the username. Environment variable: |
string |
|
Configures the password. Environment variable: |
string |
|
Configures the authentication mechanism to use if a credential was supplied. The default is unspecified, in which case the client will pick the most secure mechanism available based on the sever version. For the GSSAPI and MONGODB-X509 mechanisms, no password is accepted, only the username. Supported values: null or Environment variable: |
string |
|
Configures the source of the authentication credentials. This is typically the database that the credentials have been created. The value defaults to the database specified in the path portion of the connection string or in the 'database' configuration property. If the database is specified in neither place, the default value is Environment variable: |
string |
|
Allows passing authentication mechanism properties. Environment variable: |
|
期間フォーマットについて
期間のフォーマットは標準の 数値で始まる期間の値を指定することもできます。この場合、値が数値のみで構成されている場合、コンバーターは値を秒として扱います。そうでない場合は、 |