Description

The MongoDBInsertReceiver inserts a Domain's generated data in a JSON file directly into a MongoDB collection.


In This Article


Receiver Parameters

The following parameters can be defined for the MongoDBInsertReceiver. Items with an asterisk (*) are required: 

  • resourceName* - Defines the name of the resource that contains the database connection information on a user's local machine. 
  • databaseName* - The name of the database to access.
  • collectionName* - The name of the MongoDB collection to insert rows into.
  • truncate* - Truncates the collection before inserting rows.
  • jsonFilePath* - Defines the path to the JSON file.
  • jsonSubDir - Defines the sub-directory within the JSON file path where the JSON file for the Receiver exists.
  • jsonFileName - Defines the name of the particular JSON file within the JSON file path that needs to be read for its content and inserted into the Mongo DB collection. The Receiver parameter 'extension' value will be ignored if the value of the jsonFileName is given.
  • extension - If the Receiver parameter 'jsonFileName' is not given a value, then MongoDBInsertReceiver looks for all the files having given extension within the JSON file path for inserting data into Mongo DB collection.


Database Connectivity Properties file

A JDBC Config file (config.properties) is required to connect to a MongoDB database and contains the connection details. The format is shown below: 

host=<SERVER_IP or SERVER_NAME>
portNumber=<PORT_NUMBER>
user=<USERNAME>
password=<PASSWORD>


Example

The user in this example has read/write access to the Database where the collection is present. 

host=localhost
portNumber=27017
user=sampleOwner
password=somePassword


Kerberos Authentication Parameters

The following properties can be used to configure Kerberos Authentication. These properties need to be in the config.properties files and are an addition to the ones discussed in the previous section.


url=<mongoURL>
javax.security.auth.useSubjectCredsOnly=false
java.security.krb5.realm=<realm>
java.security.krb5.conf=<pathToKrb5Conf>
java.security.auth.login.config=<pathToGSSJaasConf>


How to check Host and Port information for MongoDB

Run the following command. It will provide the host and port information. By default, MongoDB runs on port number 27017.

sudo lsof -iTCP -sTCP:LISTEN | grep mongo


URI Connection String Format for Connecting to any MongoDB Database

The MongoDBInsertReceiver supports the URI connection string format to connect to a Mongo database.

To use the URI connection string, users need to configure their config.properties file to contain only the url property, which has the following format:


mongodb://[username:password@]host[:port][/[defaultauthdb][?options]]


Example

Here is an example config.properties file with the url property:
url=mongodb://user:password@localhost:27017/admin
Replace the user, password, host, and port information with your DB-specific details. In the above example, the Receiver will validate the mentioned user against the admin database for the MongoDB running on localhost at port 27017.



Receiver Attribute Property Keys

The Receiver defines three property keys that can be modified on any of its associated Domain Attributes:

  • columnName - Defines the name of the column as it is in the actual database table (e.g., first_name, last_name). 
  • columnType - Defines the column data type. The default is "String"
  • include - Defines if the column should be included or excluded from the insert statement.


How to Populate a Flat JSON Record into a MongoDB Collection

  1. Create/Import the Domain in the Project Version.
  2. Assign the JSONFileReceiver to the Domain. 
  3. Add another Domain and assign the MongoDBInsertReceiver to read the JSON generated by the above Receiver. 
  4. Create a Scenario for both Domains.
  5. Create a Scenario Chain, and add the two Scenarios. 
  6. Download the Scenario Chain. 
  7. Ensure you have the correct information in the connection properties file. 
  8. Run the downloaded Scenario Chain. 


How to Populate Nested JSON Record into a MongoDB Collection

  1. Import the Domains into the Project Version (e.g., JSON import).
    • Using the JSON import shortens the setup process. 
    • It will create all items to generate the nested JSON, including the Scenario Chain. 
  2. Add another Domain and assign the MongoDBInsertReceiver to read the JSON.
  3. Create a Scenario for the new Domain. 
  4. Add the Scenario to the Scenario Chain created during the JSON import (in the last position). 
  5. Download the Scenario Chain.
  6. Ensure you have the correct information in the connection properties file. 
  7. Run the downloaded Scenario Chain.