Description
Using Mongo Query, the MongoToMapGen Generator will query data from one or more database collection columns into a memory buffer. The query is executed before the first row of test data is generated. The number of rows that may be queried has no limits. Only a subset of the queried rows is kept in memory, at any given time, based on the size of the memory buffer.
This Generator should be used with the MongoFromMapGen Generator, which maps to a given column that is managed by a MongoToMapGen Generator to generate its data for a given Attribute.
Important: The MongoToMapGen and MongoFromMapGen Generators are designed to be used together.
In This Article
- MongoToMapGen Parameters
- MongoDB Query Example based on MongoToMapGen Parameters
- Sample Database Connectivity Properties file
- URI Connection String Format for Connecting to any MongoDB Database
- MongoToMapGen Configuration when setLoop is 'True' with no Query
- MongoFromMapGen Parameters
MongoToMapGen Parameters
The following parameters may be used to configure the MongoToMapGen 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 resource's name that contains the database connection information on a user's local machine.
- bufferSize* - Defines how many rows to keep in memory at a time. Note: Setting the number of rows to a very high number may cause an OutOfMemoryException if the computer does not have enough available memory. The default buffer size is 1000 rows.
- setLoop - setLoop provides the ability to OVERRIDE the loopCount, at the Scenario level, and to the number of rows that are queried. The default is set to False.
- queryOnce* - When the Domain that defines the query has a Parent Domain, it becomes a Child Domain of the Parent Domain. This flag determines if the Child Domain's query should be executed each time the Child Domain is called from the Parent Domain or if the query should only be executed once, the first time the Parent Domain calls the Child Domain. The default is set to True to query once.
- 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. Note: If there is no query, empty braces must be entered for this parameter {}. An example is provided later in this article.
- sort - Defines the sort in MongoDB Query.
- projection - Defines the projection for MongoDB Query.
- list - Stores values into a list that is used for previewing data only within the GenRocket web platform.
MongoDB Query Example based on MongoToMapGen Parameters
The following shows how the Generator Parameters correspond to a MongoDB Query:
Sample Database Connectivity Properties file
A config.properties file is required to connect to a MongoDB database. An example file is shown below:
host=localhost port=27107 user=root password=some123! database=bank
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
MongoToMapGen Configuration when setLoop is 'True' with no Query
![](https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/19106146576/original/FUrN5rKYRs9dxMrTTt2vZmVb-jr4FULoMg.png?1676309565)
MongoFromMapGen Parameters
The following parameters may be used to configure the MongoFromMapGen Generator. Parameters with an asterisk (*) are required.
- namespace - Defines a value that will uniquely define the result of the query in memory, allowing for two or more query results to exist in memory at the same time.
- columnName* - Defines the name of the column to map to within a given MongoToMapGen Generator.
- list - Stores values into a list that is used for previewing data only within the GenRocket web platform.