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.ObjectThe Write ConfigurationThe
MongoConfigfor writes- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWriteConfig.OperationTypeThe operation type for the write.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringID_FIELD_CONFIGA comma delimited field list used to identify a documentstatic java.lang.StringMAX_BATCH_SIZE_CONFIGThe maximum batch size for the batch in the bulk operation.static java.lang.StringOPERATION_TYPE_CONFIGThe write operation type to performstatic java.lang.StringORDERED_BULK_OPERATION_CONFIGUse ordered bulk operationsstatic java.lang.StringWRITE_CONCERN_JOURNAL_CONFIGThe optionalWriteConcernjournal property.static java.lang.StringWRITE_CONCERN_W_CONFIGThe optionalWriteConcernw property.static java.lang.StringWRITE_CONCERN_W_TIMEOUT_MS_CONFIGThe optionalWriteConcernwTimeout property in milliseconds.-
Fields inherited from interface com.mongodb.spark.sql.connector.config.MongoConfig
CLIENT_FACTORY_CONFIG, CLIENT_FACTORY_DEFAULT, COLLECTION_NAME_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 voiddoWithClient(java.util.function.Consumer<com.mongodb.client.MongoClient> consumer)Loans aMongoClientto the user, does not return a result.voiddoWithCollection(java.util.function.Consumer<com.mongodb.client.MongoCollection<org.bson.BsonDocument>> consumer)Loans aMongoCollectionto the user, does not return a result.booleanequals(java.lang.Object o)java.lang.StringgetCollectionName()java.lang.StringgetDatabaseName()java.util.List<java.lang.String>getIdFields()intgetMaxBatchSize()com.mongodb.client.MongoClientgetMongoClient()Returns a MongoClientWriteConfig.OperationTypegetOperationType()java.util.Map<java.lang.String,java.lang.String>getOptions()java.util.Map<java.lang.String,java.lang.String>getOriginals()com.mongodb.WriteConcerngetWriteConcern()inthashCode()booleanisOrdered()java.lang.StringtoString()<T> TwithClient(java.util.function.Function<com.mongodb.client.MongoClient,T> function)Runs a function against aMongoClient<T> TwithCollection(java.util.function.Function<com.mongodb.client.MongoCollection<org.bson.BsonDocument>,T> function)Runs a function against aMongoCollectionWriteConfigwithOption(java.lang.String key, java.lang.String value)Return aMongoConfiginstance with the extra options applied.WriteConfigwithOptions(java.util.Map<java.lang.String,java.lang.String> options)Return aMongoConfiginstance 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, 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_CONFIGor inserts the data if no match. - update: Updates an existing document that matches the
ID_FIELD_CONFIGwith 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 optionalWriteConcernw property.Users can use the name of the write concern eg:
MAJORITY,W1or 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 optionalWriteConcernjournal property.Configuration: "writeConcern.journal"
Note: Must be a boolean string:
trueorfalse.- See Also:
- Constant Field Values
-
WRITE_CONCERN_W_TIMEOUT_MS_CONFIG
public static final java.lang.String WRITE_CONCERN_W_TIMEOUT_MS_CONFIG
The optionalWriteConcernwTimeout property in milliseconds.Configuration: "writeConcern.wTimeoutMS"
Note: Must be a valid integer
- See Also:
- Constant Field Values
-
-
Method Detail
-
withOption
public WriteConfig withOption(java.lang.String key, java.lang.String value)
Description copied from interface:MongoConfigReturn aMongoConfiginstance 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:MongoConfigReturn aMongoConfiginstance 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
-
getOriginals
public java.util.Map<java.lang.String,java.lang.String> getOriginals()
- Specified by:
getOriginalsin interfaceMongoConfig- Returns:
- the original options for this MongoConfig instance
-
getOptions
public java.util.Map<java.lang.String,java.lang.String> getOptions()
- Specified by:
getOptionsin interfaceMongoConfig- Returns:
- the options for this MongoConfig instance
-
getDatabaseName
public java.lang.String getDatabaseName()
- Specified by:
getDatabaseNamein interfaceMongoConfig- Returns:
- the database name to use for this configuration
-
getCollectionName
public java.lang.String getCollectionName()
- Specified by:
getCollectionNamein interfaceMongoConfig- Returns:
- the collection name to use for this configuration
-
getMongoClient
public com.mongodb.client.MongoClient getMongoClient()
Returns a MongoClientOnce the
MongoClientis 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 aMongoClientto 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 aMongoCollectionto the user, does not return a result.- Parameters:
consumer- the consumer of theMongoCollection<BsonDocument>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
@TestOnly public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-