개요
스트리밍 모드에서 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(기본값): "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
설정의 일부로 데이터베이스, 컬렉션 및 읽기 설정을 지정하는 방법을 보여 줍니다.
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