Docs Menu
Docs Home
/
Spark 커넥터
/ /

배치(Batch) 쓰기 구성 옵션

배치 모드로 MongoDB에 데이터를 쓸 때 다음 속성을 구성할 수 있습니다.

참고

SparkConf를 사용하여 connector의 쓰기 구성을 설정하는 경우 각 속성 앞에 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 whether the connector parses the string and converts extended JSON into BSON.

This setting accepts the following values:
  • any: connector는 모든 JSON 값을 BSON으로 변환합니다.

    • "{a: 1}"{a: 1}이 됩니다.

    • "[1, 2, 3]"[1, 2, 3]이 됩니다.

    • "true"true이 됩니다.

    • "01234"1234이 됩니다.

    • "{a:b:c}" 은(는) 변하지 않습니다.

  • objectOrArrayOnly: connector는 JSON 객체와 배열만 BSON으로 변환합니다.

    • "{a: 1}"{a: 1}이 됩니다.

    • "[1, 2, 3]"[1, 2, 3]이 됩니다.

    • "true" 은(는) 변하지 않습니다.

    • "01234" 은(는) 변하지 않습니다.

    • "{a:b:c}" 은(는) 변하지 않습니다.

  • false: connector는 모든 값을 문자열로 남깁니다.

Default: false

idFieldList

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 값은 connector가 새 문서를 삽입하는지 여부를 나타냅니다.

  • update: idFieldList 값과 일치하는 기존 문서를 새 데이터로 업데이트합니다. 일치하는 항목이 없으면 upsertDocument 값은 connector가 새 문서를 삽입하는지 여부를 나타냅니다.


Default: replace

ordered

Specifies whether to perform ordered bulk operations.

Default: true

upsertDocument

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

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

Default: true

writeConcern.journal

Specifies j, a write-concern option to enable request for acknowledgment that the data is confirmed on 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 the MongoDB server guide on the WriteConcern j option.

writeConcern.w

Specifies w, a write-concern option to request 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 in the MongoDB manual.

Default: 1

writeConcern.wTimeoutMS

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

For more information on wTimeoutMS values, see the MongoDB server guide on the WriteConcern wtimeout option.

SparkConf 를 사용하여 이전 설정을 지정하는 경우 connection.uri 설정에 포함하거나 개별적으로 나열할 수 있습니다.

다음 코드 예시에서는 데이터베이스, 컬렉션, convertJson 설정을 connection.uri 설정의 일부로 지정하는 방법을 보여줍니다.

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

돌아가기

쓰기

이 페이지의 내용