MongoDB クライアントの利用
MongoDBは広く使われているNoSQLデータベースとして知られています。
このガイドでは、RESTサービスでMongoDBデータベースを使用する方法を見ていきます。
前提条件
このガイドを完成させるには、以下が必要です:
-
約15分
-
IDE
-
JDK 11+ がインストールされ、
JAVA_HOME
が適切に設定されていること -
Apache Maven 3.9.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 jakarta.enterprise.context.ApplicationScoped;
import jakarta.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();
}
}
実装は非常に簡単で、Jakarta RESTアノテーションを使ってエンドポイントを定義し、 FruitService
を使って新しい果物をリストアップ/追加するだけです。
MongoDBデータベースの設定
設定する主なプロパティーはMongoDBにアクセスするためのURLです。ほとんどすべての設定は接続URIに含めることができるので、そうすることをお勧めします。 MongoDBドキュメントで、さらに情報を得ることができます: 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
その他の設定プロパティーが必要な場合は、このガイドの最後に完全なリストがあります。
デフォルトでは、Quarkusはアプリケーション内でのJNDIの使用を制限します。これは、log4shellのような将来的な脆弱性を軽減するための予防策です。MongoDBへの接続によく使われる mongo+srv プロトコルはJNDIを必要とするため、MongoDBクライアントエクステンションを使用すると、この保護機能は自動的に無効になります。
|
開発サービス(コンフィグレーション・フリー・データベース)
QuarkusはDev Servicesと呼ばれる機能をサポートしており、設定なしで様々なデータソースを作成することができます。MongoDBの場合、このサポートはデフォルトのMongoDB接続にまで及びます。実際どう動くかというと、 quarkus.mongodb.connection-string
を設定していない場合、Quarkusはテストやdev-modeの実行時に自動的にMongoDBコンテナを起動し、接続を自動的に設定します。
MongoDB Dev Servicesは Testcontainers MongoDBモジュール をベースにしており、単一ノードのレプリカセットを起動することができます。
本番環境のアプリケーションを実行する場合、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]
.名前を省略すると、デフォルトのクライアントを設定します。
複数の MongoDB クライアントを使うことで、複数の MongoDB クラスターに接続できるようになり、MongoDB のマルチテナンシーが可能になります。+ 同じクラスター内の複数のデータベースに接続したい場合は、(JDBC接続が同じデータベース内の複数のスキーマにアクセスできるように) 1つのクライアントで同じクラスター内のすべてのデータベースにアクセスできるので、複数のクライアントは必要あり ません 。 |
名前付き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.4
Dev Servicesを使用している場合は、手動でコンテナを起動する必要はありません。 |
フロントエンドの作成
ここで、 FruitResource
と対話するための簡単なウェブページを追加してみましょう。Quarkusは、 META-INF/resources
ディレクトリーの下にある静的なリソースを自動的に提供します。 src/main/resources/META-INF/resources
ディレクトリーに、この fruits.htmlファイルの内容を含む fruits.html
ファイルを追加します。
これで、REST サービスと対話できるようになりました。
-
Quarkusを起動します。
コマンドラインインタフェースquarkus dev
Maven./mvnw quarkus:dev
Gradle./gradlew --console=plain quarkusDev
-
http://localhost:8080/fruits.html
をブラウザで開く -
フォームを使って新しいフルーツをリストに追加します。
リアクティブな MongoDB クライアント
リアクティブなMongoDBクライアントがQuarkusに含まれています。これを使うのは、古典的なMongoDBクライアントを使うのと同じくらい簡単です。先ほどの例を以下のように書き換えて使うことができます。
Mutiny
MongoDBのリアクティブ・クライアントは、Mutinyのリアクティブ・タイプを使用しています。Mutinyに慣れていない方は、 Mutiny - 直感的なリアクティブ・プログラミング・ライブラリをご覧ください。 |
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 jakarta.enterprise.context.ApplicationScoped;
import jakarta.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 jakarta.inject.Inject;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.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 codecを使ってMongoDBクライアントの利用をシンプルにする
Bson Codec
を使用することで、MongoDB クライアントは自動的に MongoDB Document
への/からのドメインオブジェクトの変換の世話をします。
まず、Bson Codec
を作成する必要があります。これは、エンティティーを MongoDB Document
に変換する方法を Bson に伝えます。ここでは CollectibleCodec
を使用しています。私たちのオブジェクトはデータベースから取得可能なので (MongoDB の識別子を持っています)、そうでなければ Codec
を使用します。詳細は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
クラスを直接使用することができます。codecは自動的に Document
を Fruit
クラスにマッピングします。
これが、 MongoCollection
を FruitCodec
と使用する例です。
package org.acme.mongodb;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.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 codec
POJO codec は、POJOをMongoDBコレクションにマッピングする方法をカスタマイズできるアノテーションのセットを提供しています。このCodecはQuarkusによって自動的に初期化されます。
このアノテーションのひとつに @BsonDiscriminator
アノテーションがありますが、これは、ドキュメントの中にデリミタフィールドを追加することで、複数の Java 型をひとつの MongoDB コレクションに保存できるようにするものです。抽象的な型やインターフェイスを扱うときに便利です。
Quarkusは、 @BsonDiscriminator
でアノテーションされたすべてのクラスをPOJO codecで自動的に登録します。
POJO Codecでは、 PropertyCodecProvider
によるジェネリックサポートが強化されています。Quarkusでは、POJO Codecで PropertyCodecProvider
を使用すると自動的に登録されます(これらのクラスは自動的に @Singleton
スコープのCDI Beanになります)。ネイティブ実行可能ファイルをビルドしてジェネリック型を使用する場合、リフレクションのために型の引数を登録する必要があるかもしれません。
PanacheでMongoDBをシンプルにする
MongoDB with Panacheエクステンションは、 Hibernate ORM with Panache にあるようなアクティブレコードスタイルのエンティティ(およびリポジトリ)を提供することで、MongoDBの利用を促進し、Quarkusでエンティティを簡単に楽しく書けるようにすることに重点を置いています。
Liquibaseによるスキーママイグレーション
Liquibase MongoDB エクステンションは、インデックスと初期データを含む MongoDB データベースの初期化を容易にします。 Liquibase が SQL データベースに提供するものと同じスキーママイグレーション機能を実装しています。
接続のヘルスチェック
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ガイドをお読みください。
テストヘルパー
Dev Services for MongoDB は、ユニットテスト用のMongoDBデータベースを起動するための最適なオプションです。
しかし、それを使用できない場合は、Quarkus が提供する 2 つの QuarkusTestResourceLifecycleManager
のいずれかを使用して MongoDB データベースを開始できます。 彼らは Flapdoodle embedded MongoDB に依存しています。
-
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のバージョンを任意に設定するには、次のコードを使用します。
使用する文字列の値は |
レガシークライアント
デフォルトではレガシーな 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 install -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 preference. Supported values are: Environment variable: |
string |
|
The database used during the readiness health checks Environment variable: |
string |
|
This property configures the DNS server. If the server is not set, it tries to read the first Environment variable: |
string |
|
This property configures the DNS server port. Environment variable: |
int |
|
If Environment variable: |
|
|
This property enables the logging ot the DNS lookup. It can be useful to understand why the lookup fails. 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 preference. 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 |
|
The credentials provider name Environment variable: |
string |
|
The credentials provider bean name.
It is the 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: |
|
|
The credentials provider name Environment variable: |
string |
|
The credentials provider bean name.
It is the Environment variable: |
string |
期間フォーマットについて
期間のフォーマットは標準の 数値で始まる期間の値を指定することもできます。この場合、値が数値のみで構成されている場合、コンバーターは値を秒として扱います。そうでない場合は、 |