Join us Sept 17 at .local NYC! Use code WEB50 to save 50% on tickets. Learn more >
MongoDB Event
Docs Menu
Docs Home
/
Spark Connector
/ /

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

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

注意

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

プロパティ名
説明

connection.uri

Required.
The connection string configuration key.

Default: mongodb://localhost:27017/

database

Required.
The database name configuration.

collection

Required.
The collection name configuration.

comment

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

Default: None

mongoClientFactory

MongoClientFactory configuration key.
You can specify a custom implementation that must implement the com.mongodb.spark.sql.connector.connection.MongoClientFactory interface.

Default: com.mongodb.spark.sql.connector.connection.DefaultMongoClientFactory

convertJson

Specifies if the connector parses string values and converts extended JSON into BSON.

This setting accepts the following values:
  • 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 のままにします。

Default: false

idFieldList

Specifies a field or list of fields by which to split the collection data. To specify more than one field, separate them using a comma as shown in the following example:
"fieldName1,fieldName2"
Default: _id

ignoreNullValues

When true, the connector ignores any null values when writing, including null values in arrays and nested documents.

Default: false

maxBatchSize

Specifies the maximum number of operations to batch in bulk operations.

Default: 512

operationType

Specifies the type of write operation to perform. You can set this to one of the following values:
  • insert: データを挿入します。

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

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


Default: replace

ordered

Specifies whether to perform ordered bulk operations.

Default: true

upsertDocument

When true, replace and update operations insert the data if no match exists.

For time series collections, you must set upsertDocument to false.

Default: 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.

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

戻る

書込み

項目一覧