Striim 3.10.1 documentation

MongoDB Writer

Writes to MongoDB collections. It may be used in four ways:

  • With an input stream of a user-defined type, MongoDB Writer writes events as documents to a single collection.

    Target document field names are taken from the input stream's event type.

    The value of the key field of the input event is used as the document key (_id field value). If the input stream's type has no key, the target document's key is generated by concatenating the values of all fields, separated by the Key Separator string. Alternatively, you may specify a subset of fields to be concatenated using the syntax <database name>.<collection name> keycolumns(<field1 name>, <field2 name>, ...) in the Collections property.

  • With an input stream of type JSONNodeEvent that is the output stream of a source using JSONParser, MongoDB Writer writes events as documents to a single collection.

    Target document field names are taken from the input events' JSON field names.

    When the JSON event contains an _id field, its value is used as the MongoDB Writer document key. Otherwise, MongoDB will generate an ObjectId for the document key.

  • With an input stream of type JSONNodeEvent that is the output stream of a MongoDBReader source, MongoDB Writer writes each MongoDB collection to a separate MongoDB collection.

    MongoDB collections may be replicated in another MongoDB instance by using wildcards in the Collections property. Alternatively, you may manually map source collections to target collections as discussed in the notes for the Collections property.

    The source document's primary key and field names are used as the target document's key and field names.

  • With an input stream of type WAEvent that is the output stream of a SQL CDC reader or DatabaseReader source, MongoDB Writer writes data from each source table to a separate collection. The target collections may be in different databases. In order to process updates and deletes, compression must be disabled in the source adapter (that is, WAEvents for insert and delete operations must contain all values, not just primary keys and, for inserts, the modified values)..

    Each row in a source table is written to a document in the target collection mapped to the table. Target document field names are taken from the source event's metadata map and their values from its data array (see WAEvent contents for change data).

    Source table data may be replicated to MongoDB collections of the same names by using wildcards in the Collections property. Note that data will be read only from tables that exist when the source starts. Additional tables added later will be ignored until the source is restarted. Alternatively, you may manually map source tables to MongoDB collections as discussed in the notes for the Collections property. When the source is a CDC reader, updates and deletes in source tables are replicated in the corresponding MongoDB target collections.

    Each source row's primary key value (which may be a composite) is used as the key (_id field value) for the corresponding MongoDB document. If the table has no primary key, the target document's key is generated by concatenating the values of all fields in the row, separated by the Key Separator string. Alternatively, you may select a subset of fields to be concatenated using the keycolumns option as discussed in the notes for the Collections property.

property

type

default value

notes

Auth DB

String

admin

Specify the authentication database for the specified username. If not specified, uses the admin database.  When the specified authType uses an external authentication server, this setting is ignored.

Auth Type

String

SCRAM_SHA_1

Specify the authentication mechanism used by your MongoDB instance. The default setting uses MongoDB's default authentication mechanism, SCRAM. Other supported values are MONGODBCR and SCRAMSHA1. Set to NoAuth if authentication is not enabled. 

GSSAPI (Kerberos), MONGODBX509, and PLAIN (LDAP) are valid values for this property, but those authentication mechanisms have not been tested so are not supported.

Batch Policy

String

EventCount:10000, Interval:30

The batch policy includes eventCount and interval (see Setting output names and rollover / upload policies for syntax). Events are buffered locally on the Striim server and sent as a batch to the target every time either of the specified values is exceeded. When the app is stopped, any remaining data in the buffer is discarded. To disable batching, set to EventCount:1,Interval:0.

With the default setting, data will be written every 30 seconds or sooner if the buffer accumulates 10,000 events.

Collections

String

The fully-qualified name(s) of the MongoDB collection(s) to write to, for example, mydb.mycollection. Separate multiple collections by commas.

You may use the % wildcard, for example, mydb.%. Note that data will be written only to collections that exist when the Striim application starts. Additional collections added later will be ignored until the application is restarted.

Connection URL

String

Specify <IP address>:< port> for the primary instance of the replica set, for example, 192.168.1.10:27107.

When connecting to a cloud instance of MongoDB, specify mongodb+srv://<host DNS name>/<database>, for example, mongodb+srv://dev-20937-liwy3.gcp.mongodb.net/mydb.

Excluded Collections

String

Any collections to be excluded from the set specified in the Collections property. Specify as for the Collections property.

Ignorable Exception Code

String

By default, if the target returns an error, the application will crash. Specify DUPLICATE_KEY or KEY_NOT_FOUND to ignore such errors and continue. To specify both, separate them with a comma.

Key Separator

String

:

Inserted between values when generating document keys by concatenating column or field values. If the values might contain a colon, change this to something that will not occur in those values.

Parallel Threads

Integer

See Creating multiple writer instances.

Password

com. webaction. security. Password

The password for the specified Username.

SSL Config

String

If using the MongoDB API for CosmosDB, set to public.

Username

String

A MongoDB user with the readwrite role on the target collection(s).

MongoDB sample applications

This application writes data from a CSV file to MongoDB. It has an input stream of a user-defined type.

CREATE SOURCE FileSource USING FileReader  ( 
  directory: '/Users/user/Desktop', 
  wildcard: 'data.csv', 
  positionbyeof: false ) 
PARSE USING DSVParser() 
OUTPUT TO FileStream;

CREATE TYPE CqStream_Type (
  uid java.lang.Integer, 
  name java.lang.String , 
  zip java.lang.Long, 
  city java.lang.String);
CREATE STREAM CqStream OF CqStream_Type;

CREATE CQ Cq1 INSERT INTO CqStream
  SELECT TO_INT(data[0]) as uid,
  data[1] as name, 
  TO_LONG(data[2]) as zip, 
  data[3] as city 
FROM FileStream;

CREATE TARGET MongoTarget USING MongoDBWriter  ( 
  Collections: 'test.emp keycolumns(uid,name)', 
  ConnectionURL: 'localhost:27017', 
  AuthDB: 'admin', 
  UserName: 'waction', 
  keyseparator: ':', 
  Password: '********') 
INPUT FROM CqStream;

This application writes data from a JSON file to MongoDB. It has an input stream of type JSONNodeEvent from JSONParser.

CREATE SOURCE JsonSource USING FileReader  ( 
  directory: '/Users/user/Desktop', 
  wildcard: 'jsondata.txt', 
  positionbyeof: false
) 
PARSE USING JSONParser() 
OUTPUT TO JsonStream;

CREATE TARGET MongoTgt USING MongoDBWriter  ( 
AuthType: 'SCRAM_SHA_1', 
  ConnectionURL: 'localhost:27017', 
  AuthDB: 'admin', 
  Collections: 'test.emp1', 
  UserName: 'waction', 
  Password: '********', 
) 
INPUT FROM JsonStream;

This initial load application writes data from one MongoDB collection to another. It has an input stream of type JSONNodeEvent from MongoDB Reader.

CREATE SOURCE Mongoource USING MongoDBReader (
  Mode: 'InitialLoad',
  collections: 'qatest.col1',
  connectionUrl: 'localhost:27017'
 )
OUTPUT TO Mongostream ;

CREATE TARGET MongoTarget USING MongoDBWriter (
  Collections: 'qatest.col1,db2.TEST',
  ServiceEndpoint: 'https://user.documents.azure.com:443/'
)
INPUT FROM Mongostream;

This streaming integration application writes data from Oracle to MongoDB. It has an input stream type of WAEvent from Oracle Reader (a SQL CDC source).

CREATE SOURCE Oracle_Source USING OracleReader  ( 
  Username: 'miner',
  Password: 'miner',
  ConnectionURL: 'jdbc:oracle:thin:@//192.168.1.49:1521/orcl',
  Tables: 'QATEST.%'
 ) 
OUTPUT TO DataStream;

CREATE TARGET MongoDBTarget1 USING MongoDBWriter  ( 
  Username: 'admin',
  Password: 'admin',
  ConnectionURL : 'localhost:27017',
  Collections: 'QATEST.%,MongoRegrDB01.%'
 ) 
INPUT FROM DataStream;