Class MongoReader


public class MongoReader extends IntegrationReader
Reads documents from a MongoDB database collection.
  • Constructor Details

    • MongoReader

      public MongoReader(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.
    • MongoReader

      public MongoReader(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

    • setQuery

      public MongoReader setQuery(String query)
      Set the JSON style query.
      (e.g. "{<field>: <value>}", "{<field>: {$in: [<value>, <value>]}}")

      Example:
      {"name": {$regex: "Cafe"}} - returns documents containing "Cafe" in the field "name".
      See MongoDB manual for more information.

      Default query is all documents ("{}"). Default is used if jsonQuery is not set, is null or empty.
      Must be set before opening the MongoReader to take effect. Otherwise default is used.
      Parameters:
      query - the JSON style query string.
    • setQuery

      public MongoReader setQuery(Record query)
      Set the JSON style query.
      (e.g. "{<field>: <value>}", "{<field>: {$in: [<value>, <value>]}}")

      Example:
      {"name": {$regex: "Cafe"}} - returns documents containing "Cafe" in the field "name".
      See MongoDB manual for more information.

      Default query is all documents ("{}"). Default is used if jsonQuery is not set, is null or empty.
      Must be set before opening the MongoReader to take effect. Otherwise default is used.
      Parameters:
      query - the JSON query as a Record.
      See Also:
    • getQuery

      public String getQuery()
      Gets the JSON style query string.
      Output format:
      (e.g. "{<field>: <value>}", "{<field>: {$in: [<value>, <value>]}}")
      See MongoDB manual for more information.
      Returns:
      the JSON query
    • isAutoCloseConnection

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

      public MongoReader setAutoCloseConnection(boolean closeConnection)
      Indicates if the MongoDB client should be closed when this reader closes (defaults to false).
    • isRemoveDocumentId

      public boolean isRemoveDocumentId()
      Indicates if the document "_id" property should be removed from the resulting records (defaults to true).
    • setRemoveDocumentId

      public MongoReader setRemoveDocumentId(boolean removeDocumentId)
      Indicates if the document "_id" property should be removed from the resulting records (defaults to true).
    • readImpl

      protected Record readImpl() throws Throwable
      Description copied from class: DataReader
      Overridden by subclasses to read the next record from this DataReader. The default implementation of DataReader.read() now insures that this method will not be called again after it returns a null.

      If no record is available, null will be returned.

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

      Specified by:
      readImpl in class DataReader
      Throws:
      Throwable
    • open

      public void open() throws DataException
      Description copied from class: DataEndpoint
      Makes this endpoint ready for reading or writing.
      Overrides:
      open in class IntegrationReader
      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 DataReader