Description
The MongoDBInsertReceiver inserts a Domain's generated data in a JSON file directly into a MongoDB collection.
In This Article
- Receiver Parameters
- Database Connectivity Properties file
- Kerberos Authentication Parameters
- How to check Host and Port information for MongoDB
- URI Connection String Format for Connecting to any MongoDB Database
- Receiver Attribute Property Keys
- How to Populate a Flat JSON Record into a MongoDB Collection
- How to Populate Nested JSON Record into a MongoDB Collection
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
mongodb://[username:password@]host[:port][/[defaultauthdb][?options]]
Example
url=mongodb://user:password@localhost:27017/admin
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
- Create/Import the Domain in the Project Version.
- Assign the JSONFileReceiver to the Domain.
- Add another Domain and assign the MongoDBInsertReceiver to read the JSON generated by the above Receiver.
- Create a Scenario for both Domains.
- Create a Scenario Chain, and add the two Scenarios.
- Download the Scenario Chain.
- Ensure you have the correct information in the connection properties file.
- Run the downloaded Scenario Chain.
How to Populate Nested JSON Record into a MongoDB Collection
- 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.
- Add another Domain and assign the MongoDBInsertReceiver to read the JSON.
- Create a Scenario for the new Domain.
- Add the Scenario to the Scenario Chain created during the JSON import (in the last position).
- Download the Scenario Chain.
- Ensure you have the correct information in the connection properties file.
- Run the downloaded Scenario Chain.