Class MongoWriter


public class MongoWriter extends IntegrationWriter
Writes records to a MongoDB database collection.
  • Constructor Details

    • MongoWriter

      public MongoWriter(String database, String collection)
      Connects to the MongoDB server in localhost on the default port 27017.
      Parameters:
      database - name of the database to be used.
      collection - name of the collection to be used.
    • MongoWriter

      public MongoWriter(MongoClient client, String database, String collection)
      Connects to the MongoDB server as specified in MongoClient. Use this to connect to non-default host and port.
      Parameters:
      client - the MongoClient instance.
      database - name of the database to be used.
      collection - name of the collection to be used.
  • Method Details

    • setBatchSize

      public MongoWriter setBatchSize(int size)
      Sets the number of records to chunk together in batch updates. Updates are not batched if this value is 1 or less. MongoWriter defaults to non batching updates.
      Parameters:
      size - the number of records to chunk together.
    • getBatchSize

      public int getBatchSize()
      Returns the number of records inserted together per batch; 1 or less inserts records one at a time (default is -1).
    • isBatchMode

      public boolean isBatchMode()
      Returns true if the batch size is greater than 1, so records are inserted in batches.
    • writeImpl

      protected void writeImpl(Record record) throws Throwable
      Description copied from class: DataWriter
      Overridden by subclasses to write the specified record to this DataWriter.

      Contract for subclasses (see also docs/authoring/DataWriter.md):

      Specified by:
      writeImpl in class DataWriter
      Throws:
      Throwable
    • isAutoCloseConnection

      public boolean isAutoCloseConnection()
      Indicates if the MongoDB client should be closed when this writer closes (defaults to false).
    • setAutoCloseConnection

      public MongoWriter setAutoCloseConnection(boolean closeConnection)
      Indicates if the MongoDB client should be closed when this writer closes (defaults to false).
    • open

      public void open() throws DataException
      Description copied from class: DataEndpoint
      Makes this endpoint ready for reading or writing.
      Overrides:
      open in class IntegrationWriter
      Throws:
      DataException
    • close

      public void close() throws DataException
      Description copied from class: DataEndpoint
      Indicates that this endpoint has finished reading or writing.
      Overrides:
      close in class DataEndpoint
      Throws:
      DataException
    • addExceptionProperties

      public DataException addExceptionProperties(DataException exception)
      Description copied from class: Endpoint
      Adds this endpoint's current state to a DataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.
      Overrides:
      addExceptionProperties in class DataWriter