Description

Using Mongo Query, the MongoEachToMapGen Generator will allow you to query one or more columns within a collection in a database allowing Find or Aggregate Query to be executed during EACH iteration of a given Generator. 


Note: Find or Aggregate Query at this level should only return one row in the result set. Even if it returns more than one row, the Generator will only retrieve the first row.

 

This Generator should be used with the MongoEachFromMapGen Generator. The MongoEachFromMapGen Generator maps to a given column that is managed by a MongoEachToMapGen Generator to generate its data for a given Attribute.

Important: The MongoEachToMapGen and MongoEachFromMapGen Generators are designed to be used together. 

 

In This Article


MongoEachToMapGen Parameters

The following parameters may be used to configure the MongoEachToMapGen Generator. Parameters with an asterisk (*) are required.

  • resourcePath* - Defines the path where the resource file for MongoDB connection properties exists.
  • resourceSubDir - Defines an optional subdirectory under the resourcePath where the resource file for MongoDB connection properties exists.
  • resourceName* - Defines the name of the resource that contains the database connection information on a user's local machine.
  • grVar1 - The first of five possible variables that may be used within the query.
  • grVar2 - The second of five possible variables that may be used within the query.
  • grVar3 - The third of five possible variables that may be used within the query.
  • grVar4 - The fourth of five possible variables that may be used within the query.
  • grVar5 - The fifth of five possible variables that may be used within the query.
  • collectionName* - Defines the collection name present in MongoDB Database.
  • methodName* - Defines the method name in MongoDB Query.
  • query - Defines the MongoDB Query to run. 
  • sort  - Defines the sort in MongoDB Query.
  • projection - Defines the projection for MongoDB Query.
  • list - Stores values into a list that is used for preview data only within the GenRocket web platform.


MongoDB Query Example based on MongoEachToMapGen Parameters

The following shows how the Generator Parameters correspond to a MongoDB Query:


Sample Database Connectivity Properties file

A JDBC Config file (config.properties) is required to connect to a MongoDB database.

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
port=27107
user=root
password=some123!
database=bank 
Java


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>


URI Connection String Format for Connecting to any MongoDB Database

The MongoEachToMapGen Generator 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


Generic
Replace the user, password, host, and port information with your DB-specific details. In the above example, the Generator is going to validate the mentioned user against the admin database for the MongoDB running on localhost at port 27017.


MongoEachFromMapGenerator Description and Parameters

The MongoEachFromMapGen Generator maps to a given column that is managed by the MongoEachToMapGen Generator to generate its data for a given Attribute.


The following parameters may be used to configure the MongoEachFromMapGen Generator. Parameters with an asterisk (*) are required.

  • columnName* - Defines the name of the column to map to within a given MongoEachToMapGen Generator.

  • list - Stores values into a list that is used for previewing data only within the GenRocket web platform.