MongoDB Plugin
The plugin provides a functionality to interact with MongoDB.
Installation
-
Copy the below line to
dependencies
section of the projectbuild.gradle
filePlease make sure to use the same version for all VIVIDUS dependencies. Example 1. build.gradleimplementation(group: 'org.vividus', name: 'vividus-plugin-mongodb', version: '0.6.2')
-
If the project was imported to the IDE before adding new dependency, re-generate the configuration files for the used IDE and then refresh the project in the used IDE.
Properties
It’s allowed to configure an unlimited number of MongoDB connections via the mechanism of the dynamic properties. The properties prefix example is:
mongodb.connection.my-mongodb-instance=mongodb+srv://username:password@mock-zzw4a.mongodb.net/test?retryWrites=true&w=majority
where my-mongodb-instance
is a key used to refer a MongoDB connection in the steps. The key is defined by users, must be unique and can’t contain dots.
Steps
Execute database command
Executes a mongo database command against a mongo database and saves the command result to a variable
|
When I execute command `$command` against `$dbName` database on `$instanceKey` MongoDB instance and save result to $scopes variable `$variableName`
-
$command
- The database command to execute -
$dbName
- The database name -
$instanceKey
- The key of a particular connection undermongodb.connection.
prefix -
$variableName
- The variable name to store results in JSON format.
When I execute command `
{
find: "employees",
filter: { age: { $gte: 20 } },
sort: { age: 1 },
projection: { age: 1, name: 1, _id: 0 },
batchSize: 500
}
` against `users` database on `my-mongodb-instance` MongoDB instance and save result to SCENARIO variable `find`
Execute chained commands
Executes an assembled sequence of predefined commands against a mongo database and saves the result to a variable
Name | Type | Description | Example |
---|---|---|---|
find |
source |
selects documents in a collection, takes JSON as an argument |
|
projection |
intermediate |
determine which fields to include in the returned documents, takes JSON as an argument |
|
count |
terminal |
counts the number of documents in a collection, takes no arguments |
|
collect |
terminal |
collects previously found documents into JSON format, takes no arguments |
|
When I execute commands $commands in `$collectionName` collection against `$dbName` database on `$instanceKey` MongoDB instance and save result to $scopes variable `$variableName`
-
$commands
- The sequence of commands to execute -
$collectionName
- The collection name to retrieve documents from -
$dbName
- The database name -
$instanceKey
- Key of a particular connection undermongodb.connection.
prefix -
$variableName
- The variable name to store results in JSON format.
When I execute commands
|command |argument |
|find |{ age: { $gte: 20 } } |
|projection|{ age: 1, name: 1, _id: 0 }|
|count | |
in `employees` collection against `users` database on `my-mongodb-instance` MongoDB instance and save result to SCENARIO variable `find`