AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

バッチ書込み (write) 構成オプション

バッチ モードで MongoDB にデータを書き込むときに、次のプロパティを構成できます。

注意

SparkConfを使用して connectorの書込み構成を設定する場合は、各プロパティの前にspark.mongodb.write.を付けます。

プロパティ名
説明

connection.uri

必須。
接続文字列の構成キー。

デフォルト: mongodb://localhost:27017/

database

必須。
データベース名の構成。

collection

必須。
コレクション名の構成。

comment

The comment to append to the write operation. Comments appear in the output of the Database Profiler.

Default: None

mongoClientFactory

MongoClientFactory の設定キー。
com.mongodb.spark.sql.connector.connection.MongoClientFactory インターフェースを実装する必要があるカスタム実装を指定できます。

デフォルト: com.mongodb.spark.sql.connector.connection.DefaultMongoClientFactory

convertJson

コネクタがstring値を解析し、拡張JSONをBSONに変換するかどうかを指定します。

この設定では、次の値を受け入れることができます:

  • any: コネクタはすべての JSON 値を BSON に変換します。

    • "{a: 1}" は{a: 1}になります。

    • "[1, 2, 3]" は[1, 2, 3]になります。

    • "true" はtrueになります。

    • "01234" は1234になります。

    • "{a:b:c}" は変更されません。

  • objectOrArrayOnly: コネクタは JSON オブジェクトと配列のみを BSON に変換します。

    • "{a: 1}" は{a: 1}になります。

    • "[1, 2, 3]" は[1, 2, 3]になります。

    • "true" は変更されません。

    • "01234" は変更されません。

    • "{a:b:c}" は変更されません。

  • false: コネクタはすべての値を string のままにします。

デフォルト: false

idFieldList

コレクション データを分裂するフィールドまたはフィールドのリストを指定します。複数のフィールドを指定するには、次の例に示すようにカンマを使用して区切ります。

"fieldName1,fieldName2"

デフォルト: _id

ignoreNullValues

true の場合、コネクターは書き込み時に、配列とネストされたドキュメントの null 値を含め、あらゆる null 値を無視します。

デフォルト: false

maxBatchSize

バルク操作でバッチする操作の最大数を指定します。

デフォルト: 512

operationType

実行する書込み (write) 操作のタイプを指定します。 これは、次のいずれかの値に設定できます。

  • insert: データを挿入します。

  • replace: idFieldList値に一致する既存のドキュメントを新しいデータに置き換えます。 一致するものが存在しない場合、 upsertDocumentの値はコネクタが新しいドキュメントを挿入するかどうかを示します。

  • update: idFieldList値に一致する既存のドキュメントを新しいデータで更新します。 一致するものが存在しない場合、 upsertDocumentの値はコネクタが新しいドキュメントを挿入するかどうかを示します。


デフォルト: replace

ordered

オーダードバルク操作を実行するかどうかを指定します。

デフォルト: true

upsertDocument

true の場合、置換および更新操作では、一致するものがない場合にデータが挿入されます。

時系列コレクションの場合は、upsertDocument を false に設定する必要があります。

デフォルト: true

writeConcern.w

Specifies w, a write-concern option requesting acknowledgment that the write operation has propagated to a specified number of MongoDB nodes.

For a list of allowed values for this option, see WriteConcern w Option in the MongoDB Server manual.

Default: Acknowledged

writeConcern.journal

Specifies j, a write-concern option requesting acknowledgment that the data has been written to the on-disk journal for the criteria specified in the w option. You can specify either true or false.

For more information on j values, see WriteConcern j Option in the MongoDB Server manual.

writeConcern.wTimeoutMS

Specifies wTimeoutMS, a write-concern option to return an error when a write operation exceeds the specified number of milliseconds. If you use this optional setting, you must specify a nonnegative integer.

For more information on wTimeoutMS values, see WriteConcern wtimeout in the MongoDB Server manual.

ignoreDuplicatesOnInsert

trueに設定すると、コネクターは順序なしの挿入操作の実行時に重複キーエラーを無視します。挿入されるデータには、_id フィールド値または idFieldList オプションで指定されたフィールドが含まれている必要があります。

デフォルト: false

SparkConfを使用して以前の設定のいずれかを指定する場合は、それらをconnection.uri設定に含めるか、個別に一覧表示できます。

次のコード例は、 connection.uri設定の一部としてデータベース、コレクション、およびconvertJson設定を指定する方法を示しています。

spark.mongodb.write.connection.uri=mongodb://127.0.0.1/myDB.myCollection?convertJson=any

connection.uriを短くして設定を読みやすくするには、代わりにこれらを個別に指定します。

spark.mongodb.write.connection.uri=mongodb://127.0.0.1/
spark.mongodb.write.database=myDB
spark.mongodb.write.collection=myCollection
spark.mongodb.write.convertJson=any

重要

connection.uriとその行の両方に 設定を指定すると、 connection.uriの設定が優先されます。 たとえば、次の構成では、接続データベースはfoobarです。

spark.mongodb.write.connection.uri=mongodb://127.0.0.1/foobar
spark.mongodb.write.database=bar