Class WriteConfig
- java.lang.Object
-
- com.mongodb.spark.sql.connector.config.WriteConfig
-
- All Implemented Interfaces:
MongoConfig
,java.io.Serializable
public final class WriteConfig extends java.lang.Object
The Write ConfigurationThe
MongoConfig
for writes- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WriteConfig.ConvertJson
The convert json configuration.static class
WriteConfig.OperationType
The operation type for the write.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CONVERT_JSON_CONFIG
Convert JSON and extended JSON values into their BSON equivalent.static java.lang.String
ID_FIELD_CONFIG
A comma delimited field list used to identify a documentstatic java.lang.String
IGNORE_NULL_VALUES_CONFIG
Ignore null values, even those within arrays or documents.static java.lang.String
MAX_BATCH_SIZE_CONFIG
The maximum batch size for the batch in the bulk operation.static java.lang.String
OPERATION_TYPE_CONFIG
The write operation type to performstatic java.lang.String
ORDERED_BULK_OPERATION_CONFIG
Use ordered bulk operationsstatic java.lang.String
UPSERT_DOCUMENT_CONFIG
Upsert documents, when using replace or update operations.static java.lang.String
WRITE_CONCERN_JOURNAL_CONFIG
The optionalWriteConcern
journal property.static java.lang.String
WRITE_CONCERN_W_CONFIG
The optionalWriteConcern
w property.static java.lang.String
WRITE_CONCERN_W_TIMEOUT_MS_CONFIG
The optionalWriteConcern
wTimeout property in milliseconds.-
Fields inherited from interface com.mongodb.spark.sql.connector.config.MongoConfig
CLIENT_FACTORY_CONFIG, CLIENT_FACTORY_DEFAULT, COLLECTION_NAME_CONFIG, COMMENT_CONFIG, CONNECTION_STRING_CONFIG, CONNECTION_STRING_DEFAULT, DATABASE_NAME_CONFIG, PREFIX, READ_PREFIX, WRITE_PREFIX
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WriteConfig.ConvertJson
convertJson()
void
doWithClient(java.util.function.Consumer<com.mongodb.client.MongoClient> consumer)
Loans aMongoClient
to the user, does not return a result.void
doWithCollection(java.util.function.Consumer<com.mongodb.client.MongoCollection<org.bson.BsonDocument>> consumer)
Loans aMongoCollection
to the user, does not return a result.boolean
equals(java.lang.Object o)
java.lang.String
getCollectionName()
java.lang.String
getDatabaseName()
java.util.List<java.lang.String>
getIdFields()
int
getMaxBatchSize()
com.mongodb.client.MongoClient
getMongoClient()
Returns a MongoClientWriteConfig.OperationType
getOperationType()
java.util.Map<java.lang.String,java.lang.String>
getOptions()
java.util.Map<java.lang.String,java.lang.String>
getOriginals()
com.mongodb.WriteConcern
getWriteConcern()
int
hashCode()
boolean
ignoreNullValues()
boolean
isOrdered()
boolean
isUpsert()
java.lang.String
toString()
<T> T
withClient(java.util.function.Function<com.mongodb.client.MongoClient,T> function)
Runs a function against aMongoClient
<T> T
withCollection(java.util.function.Function<com.mongodb.client.MongoCollection<org.bson.BsonDocument>,T> function)
Runs a function against aMongoCollection
WriteConfig
withOption(java.lang.String key, java.lang.String value)
Return aMongoConfig
instance with the extra options applied.WriteConfig
withOptions(java.util.Map<java.lang.String,java.lang.String> options)
Return aMongoConfig
instance with the extra options applied.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.mongodb.spark.sql.connector.config.MongoConfig
containsKey, get, getBoolean, getComment, getConnectionString, getDouble, getInt, getList, getLong, getNamespace, getOrDefault, subConfiguration, toReadConfig, toWriteConfig
-
-
-
-
Field Detail
-
MAX_BATCH_SIZE_CONFIG
public static final java.lang.String MAX_BATCH_SIZE_CONFIG
The maximum batch size for the batch in the bulk operation.Configuration: "maxBatchSize"
Default: 512
- See Also:
- Constant Field Values
-
ORDERED_BULK_OPERATION_CONFIG
public static final java.lang.String ORDERED_BULK_OPERATION_CONFIG
Use ordered bulk operationsConfiguration: "ordered"
Default: true
- See Also:
- Constant Field Values
-
OPERATION_TYPE_CONFIG
public static final java.lang.String OPERATION_TYPE_CONFIG
The write operation type to performThe options are:
- insert: Inserts the data.
- replace: Replaces an existing document that matches the
ID_FIELD_CONFIG
or inserts the data if no match. - update: Updates an existing document that matches the
ID_FIELD_CONFIG
with the new data or inserts the data if no match.
Configuration: "operationType"
Default: "replace"
- See Also:
- Constant Field Values
-
ID_FIELD_CONFIG
public static final java.lang.String ID_FIELD_CONFIG
A comma delimited field list used to identify a documentConfiguration: "idFieldList"
Default: "[_id]".
Note: For sharded clusters use the shard key.
- See Also:
- Constant Field Values
-
WRITE_CONCERN_W_CONFIG
public static final java.lang.String WRITE_CONCERN_W_CONFIG
The optionalWriteConcern
w property.Users can use the name of the write concern eg:
MAJORITY
,W1
or they can provide the number of MongoDB's required to acknowledge the write before continuing.Configuration: "writeConcern.w"
Note: The default write concern is
WriteConcern.ACKNOWLEDGED
.- See Also:
- Constant Field Values
-
WRITE_CONCERN_JOURNAL_CONFIG
public static final java.lang.String WRITE_CONCERN_JOURNAL_CONFIG
The optionalWriteConcern
journal property.Configuration: "writeConcern.journal"
Note: Must be a boolean string:
true
orfalse
.- See Also:
- Constant Field Values
-
WRITE_CONCERN_W_TIMEOUT_MS_CONFIG
public static final java.lang.String WRITE_CONCERN_W_TIMEOUT_MS_CONFIG
The optionalWriteConcern
wTimeout property in milliseconds.Configuration: "writeConcern.wTimeoutMS"
Note: Must be a valid integer
- See Also:
- Constant Field Values
-
UPSERT_DOCUMENT_CONFIG
public static final java.lang.String UPSERT_DOCUMENT_CONFIG
Upsert documents, when using replace or update operations.Configuration: "upsertDocument"
Default: true
- Since:
- 10.1
- See Also:
- Constant Field Values
-
CONVERT_JSON_CONFIG
public static final java.lang.String CONVERT_JSON_CONFIG
Convert JSON and extended JSON values into their BSON equivalent.Configuration: "convertJson"
Default: 'false'
- Since:
- 10.1
- See Also:
- Constant Field Values
-
IGNORE_NULL_VALUES_CONFIG
public static final java.lang.String IGNORE_NULL_VALUES_CONFIG
Ignore null values, even those within arrays or documents.Configuration: "ignoreNullValues"
Default: false
If true, will store only store non-null values.
- Since:
- 10.1
- See Also:
- Constant Field Values
-
-
Method Detail
-
withOption
public WriteConfig withOption(java.lang.String key, java.lang.String value)
Description copied from interface:MongoConfig
Return aMongoConfig
instance with the extra options applied.Existing configurations may be overwritten by the new options.
- Parameters:
key
- the key to addvalue
- the value to add- Returns:
- a new MongoConfig
-
withOptions
public WriteConfig withOptions(java.util.Map<java.lang.String,java.lang.String> options)
Description copied from interface:MongoConfig
Return aMongoConfig
instance with the extra options applied.Existing configurations may be overwritten by the new options.
- Parameters:
options
- the context specific options.- Returns:
- a new MongoConfig
-
getMaxBatchSize
public int getMaxBatchSize()
- Returns:
- the max size of bulk operation batches
-
getOperationType
public WriteConfig.OperationType getOperationType()
- Returns:
- the operation type
-
getWriteConcern
public com.mongodb.WriteConcern getWriteConcern()
- Returns:
- the write concern to sue
-
getIdFields
public java.util.List<java.lang.String> getIdFields()
- Returns:
- the field list used to identify the document
-
isOrdered
public boolean isOrdered()
- Returns:
- true if the bulk operation is ordered
-
isUpsert
public boolean isUpsert()
- Returns:
- true if should use an upsert
-
convertJson
public WriteConfig.ConvertJson convertJson()
- Returns:
- the ConvertJson value regarding string parsing
- Since:
- 10.1
-
ignoreNullValues
public boolean ignoreNullValues()
- Returns:
- the true if null values should be ignored, even those within arrays or documents
- Since:
- 10.1
-
getOriginals
public java.util.Map<java.lang.String,java.lang.String> getOriginals()
- Specified by:
getOriginals
in interfaceMongoConfig
- Returns:
- the original options for this MongoConfig instance
-
getOptions
public java.util.Map<java.lang.String,java.lang.String> getOptions()
- Specified by:
getOptions
in interfaceMongoConfig
- Returns:
- the options for this MongoConfig instance
-
getDatabaseName
public java.lang.String getDatabaseName()
- Specified by:
getDatabaseName
in interfaceMongoConfig
- Returns:
- the database name to use for this configuration
-
getCollectionName
public java.lang.String getCollectionName()
- Specified by:
getCollectionName
in interfaceMongoConfig
- Returns:
- the collection name to use for this configuration
-
getMongoClient
public com.mongodb.client.MongoClient getMongoClient()
Returns a MongoClientOnce the
MongoClient
is no longer required, it MUST be closed by callingmongoClient.close()
.- Returns:
- the MongoClient from the cache or create a new one using the
MongoClientFactory
.
-
withClient
public <T> T withClient(java.util.function.Function<com.mongodb.client.MongoClient,T> function)
Runs a function against aMongoClient
- Type Parameters:
T
- The return type- Parameters:
function
- the function that is passed theMongoClient
- Returns:
- the result of the function
-
doWithClient
public void doWithClient(java.util.function.Consumer<com.mongodb.client.MongoClient> consumer)
Loans aMongoClient
to the user, does not return a result.- Parameters:
consumer
- the consumer of theMongoClient
-
withCollection
public <T> T withCollection(java.util.function.Function<com.mongodb.client.MongoCollection<org.bson.BsonDocument>,T> function)
Runs a function against aMongoCollection
- Type Parameters:
T
- The return type- Parameters:
function
- the function that is passed theMongoCollection
- Returns:
- the result of the function
-
doWithCollection
public void doWithCollection(java.util.function.Consumer<com.mongodb.client.MongoCollection<org.bson.BsonDocument>> consumer)
Loans aMongoCollection
to the user, does not return a result.- Parameters:
consumer
- the consumer of theMongoCollection<BsonDocument>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
@TestOnly public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-