Skip to main content

mongodb (Store)

Using this extension a MongoDB Event Table can be configured to persist events in a MongoDB of user's choice.

Syntax

@Store(type="mongodb", mongodb.uri="<STRING>", collection.name="<STRING>", secure.connection="<STRING>", trust.store="<STRING>", trust.store.password="<STRING>", key.store="<STRING>", key.store.password="<STRING>")
@PrimaryKey("PRIMARY_KEY")
@Index("INDEX")

Query Parameters

NameDescriptionDefault ValuePossible Data TypesOptionalDynamic
mongodb.uriThe MongoDB URI for the MongoDB data store. The uri must be of the format mongodb://[username:password@]host1[:port1],hostN[:portN]][/[database][?options]] The options specified in the uri will override any connection options specified in the deployment yaml file. Note: The user should have read permissions to the admindb as well as read/write permissions to the database accessed.STRINGNoNo
collection.nameThe name of the collection in the store this Event Table should be persisted as.Name of the stream processor event table.STRINGYesNo
secure.connectionDescribes enabling the SSL for the mongodb connectionfalseSTRINGYesNo
trust.storeFile path to the trust store.\${carbon.home}/resources/security/client-truststore.jksSTRINGYesNo
trust.store.passwordPassword to access the trust storegdncarbonSTRINGYesNo
key.storeFile path to the keystore.\${carbon.home}/resources/security/client-truststore.jksSTRINGYesNo
key.store.passwordPassword to access the keystoregdncarbonSTRINGYesNo

System Parameters

NameDescriptionDefault ValuePossible Parameters
applicationNameSets the logical name of the application using this MongoClient. The application name may be used by the client to identify the application to the server, for use in server logs, slow query logs, and profile collection.nullthe logical name of the application using this MongoClient. The UTF-8 encoding may not exceed 128 bytes.
cursorFinalizerEnabledSets whether cursor finalizers are enabled.truetrue false
requiredReplicaSetNameThe name of the replica setnullthe logical name of the replica set
sslEnabledSets whether to initiate connection with TSL/SSL enabled. true: Initiate the connection with TLS/SSL. false: Initiate the connection without TLS/SSL.falsetrue false
trustStoreFile path to the trust store.\${carbon.home}/resources/security/client-truststore.jksAny valid file path.
trustStorePasswordPassword to access the trust storegdncarbonAny valid password.
keyStoreFile path to the keystore.\${carbon.home}/resources/security/client-truststore.jksAny valid file path.
keyStorePasswordPassword to access the keystoregdncarbonAny valid password.
connectTimeoutThe time in milliseconds to attempt a connection before timing out.10000Any positive integer
connectionsPerHostThe maximum number of connections in the connection pool.100Any positive integer
minConnectionsPerHostThe minimum number of connections in the connection pool.0Any natural number
maxConnectionIdleTimeThe maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed. A zero value indicates no limit to the idle time. A pooled connection that has exceeded its idle time will be closed and replaced when necessary by a new connection.0Any positive integer
maxWaitTimeThe maximum wait time in milliseconds that a thread may wait for a connection to become available. A value of 0 means that it will not wait. A negative value means to wait indefinitely120000Any integer
threadsAllowedToBlockForConnectionMultiplierThe maximum number of connections allowed per host for this MongoClient instance. Those connections will be kept in a pool when idle. Once the pool is exhausted, any operation requiring a connection will block waiting for an available connection.100Any natural number
maxConnectionLifeTimeThe maximum life time of a pooled connection. A zero value indicates no limit to the life time. A pooled connection that has exceeded its life time will be closed and replaced when necessary by a new connection.0Any positive integer
socketKeepAliveSets whether to keep a connection alive through firewallsfalsetrue false
socketTimeoutThe time in milliseconds to attempt a send or receive on a socket before the attempt times out. Default 0 means never to timeout.0Any natural integer
writeConcernThe write concern to use.acknowledgedacknowledged w1 w2 w3 unacknowledged fsynced journaled replica_acknowledged normal safe majority fsync_safe journal_safe replicas_safe
readConcernThe level of isolation for the reads from replica sets.defaultlocal majority linearizable
readPreferenceSpecifies the replica set read preference for the connection.primaryprimary secondary secondarypreferred primarypreferred nearest
localThresholdThe size (in milliseconds) of the latency window for selecting among multiple suitable MongoDB instances.15Any natural number
serverSelectionTimeoutSpecifies how long (in milliseconds) to block for server selection before throwing an exception. A value of 0 means that it will timeout immediately if no server is available. A negative value means to wait indefinitely.30000Any integer
heartbeatSocketTimeoutThe socket timeout for connections used for the cluster heartbeat. A value of 0 means that it will timeout immediately if no cluster member is available. A negative value means to wait indefinitely.20000Any integer
heartbeatConnectTimeoutThe connect timeout for connections used for the cluster heartbeat. A value of 0 means that it will timeout immediately if no cluster member is available. A negative value means to wait indefinitely.20000Any integer
heartbeatFrequencySpecify the interval (in milliseconds) between checks, counted from the end of the previous check until the beginning of the next one.10000Any positive integer
minHeartbeatFrequencySets the minimum heartbeat frequency. In the event that the SDK has to frequently re-check a server's availability, it will wait at least this long since the previous check to avoid wasted effort.500Any positive integer

Example 1

@PrimaryKey("symbol")
@Index("volume:1", {background:true,unique:true}")
CREATE STORE FooTable WITH (type="mongodb",mongodb.uri="mongodb://admin:admin@localhost/Foo") (symbol string, price float, volume long);

This will create a collection called FooTable for the events to be saved with symbol as Primary Key(unique index at mongoDB level) and index for the field volume will be created in ascending order with the index option to create the index in the background. Note: @PrimaryKey: This specifies a list of comma-separated values to be treated as unique fields in the table. Each record in the table must have a unique combination of values for the fields specified here. @Index: This specifies the fields that must be indexed at the database level. You can specify multiple values as a come-separated list. A single value to be in the format, <FieldName>:<SortOrder>. The last element is optional through which a valid index options can be passed.

<SortOrder>: 1 for Ascending & -1 for Descending. Optional, with default value as 1. <IndexOptions>: Index Options must be defined inside curly brackets.

Options must follow the standard mongodb index options format. https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/ Example 1: @Index('symbol:1', '{"unique":true}') Example 2: @Index('symbol', '{"unique":true}') Example 3: @Index('symbol:1', 'volume:-1', '{"unique":true}')