Overview
ストリーミング モードで MongoDB からデータを読み取るときに、次のプロパティを構成できます。
注意
SparkConf
を使用してコネクタの読み取り構成を設定する場合は、各プロパティの前にspark.mongodb.read.
を付けます。
プロパティ名 | 説明 | ||
---|---|---|---|
| Required. The connection string configuration key. Default: mongodb://localhost:27017/ | ||
| Required. The database name configuration. | ||
| Required. The collection name configuration. | ||
| The comment to append to the read operation. Comments appear in the
output of the Database Profiler. Default: None | ||
| MongoClientFactory configuration key. You can specify a custom implementation, which must implement the
com.mongodb.spark.sql.connector.connection.MongoClientFactory
interface.Default: com.mongodb.spark.sql.connector.connection.DefaultMongoClientFactory | ||
| Specifies a custom aggregation pipeline to apply to the collection
before sending data to Spark. The value must be either an extended JSON single document or list
of documents. A single document resembles the following:
A list of documents resembles the following:
カスタム集計パイプラインは、パーティショニング戦略と互換性がある必要があります。 たとえば、 | ||
| Specifies whether to allow storage to disk when running the
aggregation. Default: true | ||
| Change stream configuration prefix. See the
Change Stream Configuration section for more
information about change streams. | ||
| When true , the connector converts BSON types not supported by Spark into
extended JSON strings.
When false , the connector uses the original relaxed JSON format for
unsupported types.Default: false |
ストリーム構成の変更
MongoDB から変更ストリームを読み取るときに、次のプロパティを構成できます。
プロパティ名 | 説明 |
---|---|
| アップデート操作時に変更ストリームが返す値を決定します。 デフォルト設定では、元のドキュメントと更新されたドキュメントの差が返されます。
この変更ストリーム オプションの機能の詳細については、MongoDB サーバー マニュアル ガイド「 更新操作のための完全なドキュメントの検索 」を参照してください。 デフォルト: "default" |
| The maximum number of partitions the Spark Connector divides each
micro-batch into. Spark workers can process these partitions in parallel. This setting applies only when using micro-batch streams. Default: 1 警告: |
| Specifies whether to publish the changed document or the full
change stream document. When this setting is false , you must specify a schema. The schema
must include all fields that you want to read from the change stream. You can
use optional fields to ensure that the schema is valid for all change-stream
events.When this setting is true , the connector exhibits the following behavior:
この設定は デフォルト: |
| Specifies how the connector starts up when no offset is available. This setting accepts the following values:
|
でのプロパティの指定 connection.uri
SparkConfを使用して以前の設定のいずれかを指定する場合は、それらをconnection.uri
設定に含めるか、個別に一覧表示できます。
次のコード例は、 connection.uri
設定の一部としてデータベース、コレクション、読み込み設定(read preference)を指定する方法を示しています。
spark.mongodb.read.connection.uri=mongodb://127.0.0.1/myDB.myCollection?readPreference=primaryPreferred
connection.uri
を短くして設定を読みやすくするには、代わりにこれらを個別に指定します。
spark.mongodb.read.connection.uri=mongodb://127.0.0.1/ spark.mongodb.read.database=myDB spark.mongodb.read.collection=myCollection spark.mongodb.read.readPreference.name=primaryPreferred
重要
connection.uri
とその行の両方に 設定を指定すると、 connection.uri
の設定が優先されます。 たとえば、次の構成では、接続データベースはfoobar
です。これはconnection.uri
設定の 値であるためです。
spark.mongodb.read.connection.uri=mongodb://127.0.0.1/foobar spark.mongodb.read.database=bar