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

스트리밍 읽기 구성 옵션

스트리밍 모드에서 MongoDB의 데이터를 읽을 때 다음 속성을 구성할 수 있습니다.

참고

SparkConf를 사용하여 커넥터의 읽기 구성을 설정하는 경우 각 속성 앞에 spark.mongodb.read.를 접두사로 붙입니다.

속성 이름
설명

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 read operation. Comments appear in the output of the Database Profiler.

Default: None

mongoClientFactory

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

aggregation.pipeline

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:
{"$match": {"closed": false}}
A list of documents resembles the following:
[{"$match": {"closed": false}}, {"$project": {"status": 1, "name": 1, "description": 1}}]

사용자 지정 집계 파이프라인은 파티셔너 전략과 호환되어야 합니다. 예를 들어 $group 같은 집계 단계는 파티션을 두 개 이상 생성하는 파티셔너에서는 작동하지 않습니다.

aggregation.allowDiskUse

Specifies whether to allow storage to disk when running the aggregation.

Default: true

change.stream.

Change stream configuration prefix.
See the Change Stream Configuration section for more information about change streams.

outputExtendedJson

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에서 변경 스트림을 읽을 때 다음 속성을 구성할 수 있습니다.

속성 이름
설명

change.stream.lookup.full.document

업데이트 작업 시 변경 스트림이 반환하는 값을 결정합니다.

기본 설정은 소스 문서와 업데이트된 문서 간의 차이점을 반환합니다.

updateLookup 설정은 원본 문서와 업데이트된 문서 간의 차이점도 반환하지만 업데이트된 문서 전체의 사본도 포함합니다.

이 변경 스트림 옵션의 작동 방식에 대한 자세한 내용은 MongoDB 서버 매뉴얼 가이드 업데이트 작업을 위한 전체 문서 조회를 참조하세요.

Default(기본값): "default"

change.stream.micro.batch.max.partition.count

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

경고: 1 보다 큰 값을 지정하면 Spark Connector 가 변경 이벤트를 처리하는 순서가 변경될 수 있습니다. 순서가 맞지 않는 처리 로 인해 다운스트림에 데이터 불일치가 발생할 수 있는 경우 이 설정을 피하세요.

change.stream.publish.full.document.only

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:
  • connector 는 fullDocument 필드가 생략된 메시지를 필터링하고 필드 값만 게시합니다.

  • 스키마 지정하지 않으면 connector 기본 컬렉션 이 아닌 변경 스트림 문서 에서 스키마 유추합니다.

이 설정은 change.stream.lookup.full.document 설정을 재정의합니다.

기본값: false

change.stream.startup.mode

Specifies how the connector starts up when no offset is available.
This setting accepts the following values:

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

돌아가기

읽기

이 페이지의 내용