Class WriteConfig

  • All Implemented Interfaces:
    MongoConfig, java.io.Serializable

    public final class WriteConfig
    extends java.lang.Object
    The Write Configuration

    The MongoConfig for writes

    See Also:
    Serialized Form
    • 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 operations

        Configuration: "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 perform

        The 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 document

        Configuration: "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 optional WriteConcern 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 optional WriteConcern journal property.

        Configuration: "writeConcern.journal"

        Note: Must be a boolean string: true or false.

        See Also:
        Constant Field Values
      • WRITE_CONCERN_W_TIMEOUT_MS_CONFIG

        public static final java.lang.String WRITE_CONCERN_W_TIMEOUT_MS_CONFIG
        The optional WriteConcern wTimeout 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: MongoConfig
        Return a MongoConfig instance with the extra options applied.

        Existing configurations may be overwritten by the new options.

        Parameters:
        key - the key to add
        value - 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 a MongoConfig 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
      • 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:
        getOriginals in interface MongoConfig
        Returns:
        the original options for this MongoConfig instance
      • getOptions

        public java.util.Map<java.lang.String,​java.lang.String> getOptions()
        Specified by:
        getOptions in interface MongoConfig
        Returns:
        the options for this MongoConfig instance
      • getDatabaseName

        public java.lang.String getDatabaseName()
        Specified by:
        getDatabaseName in interface MongoConfig
        Returns:
        the database name to use for this configuration
      • getCollectionName

        public java.lang.String getCollectionName()
        Specified by:
        getCollectionName in interface MongoConfig
        Returns:
        the collection name to use for this configuration
      • getMongoClient

        public com.mongodb.client.MongoClient getMongoClient()
        Returns a MongoClient

        Once the MongoClient is no longer required, it MUST be closed by calling mongoClient.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 a MongoClient
        Type Parameters:
        T - The return type
        Parameters:
        function - the function that is passed the MongoClient
        Returns:
        the result of the function
      • doWithClient

        public void doWithClient​(java.util.function.Consumer<com.mongodb.client.MongoClient> consumer)
        Loans a MongoClient to the user, does not return a result.
        Parameters:
        consumer - the consumer of the MongoClient
      • withCollection

        public <T> T withCollection​(java.util.function.Function<com.mongodb.client.MongoCollection<org.bson.BsonDocument>,​T> function)
        Runs a function against a MongoCollection
        Type Parameters:
        T - The return type
        Parameters:
        function - the function that is passed the MongoCollection
        Returns:
        the result of the function
      • doWithCollection

        public void doWithCollection​(java.util.function.Consumer<com.mongodb.client.MongoCollection<org.bson.BsonDocument>> consumer)
        Loans a MongoCollection to the user, does not return a result.
        Parameters:
        consumer - the consumer of the MongoCollection<BsonDocument>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        @TestOnly
        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object