MongoDB plugin

Overview

The MongoDB plugin connects QALIPSIS to MongoDb.

Technology addressed

MongoDB: https://mongodb.com/

Dependency

io.qalipsis.plugin:qalipsis-plugin-mongodb

Namespace in scenario

mongodb()

Client library

MongoDB Reactive Streams Driver: refer to MongoDB Java Reactive Streams.

Supported steps
  • poll: polls the newest data periodically.

  • save: saves a batch of documents generated from the input and step context.

  • search: searches documents and builds a query from the input and step context.

Example scenarios using a combination of MongoDB supported steps are provided on GitHub.

Poll step

The poll step within the MongoDB plugin polls the newest records from a database table, with a delay between each execution.

Ancestor

Scenario

Functionality

The poll step is created only once in a scenario; it is then used throughout the scenario as called. The poll step within the MongoDB plugin uses a strategy of “delivered at least once”.

Example
mongodb().poll {
    name = "poll"
    connect {
        MongoClients.create("mongodb://James23:SantaFe1987@localhost:27017")
    }
    search {
        database = "iot"
        collection = "batteryState"
        query = Document()
        sort = linkedMapOf("deviceId" to Sorting.ASC)
        tieBreaker = "deviceId"
    }
    pollDelay(Duration.ofSeconds(1))
}
Notable parameters
  • connect (required): configures the connection to MongoDb.

  • query (required): specifies a document respecting the requirements of the target database.

  • tieBreaker (required): repeats the first column used for sorting and comparison ( or >=, depending on the ascending or descending order).

  • parameters (optional): binds values to the clauses of the prepared query.

  • pollDelay (required): specifies the delay between query executions.

  • broadcast (optional): specifies the broadcast parameters for the step.

Tips
  • Use the poll step with a join operator if you need to verify the values saved by your tested system in the database.

  • The query parameter requires at least one sorting field (tiebreaker in the example) to filter the newest results and not fetch the same records repeatedly.

  • The latest known value for tiebreaker is used to filter out the values already received from the database.

Reference Documentation

Refer to the Mongodb documentation for further parameter and configuration information.

Save step

The save step within the MongoDB plugin persists a batch of documents into MongoDB.

Ancestor

Step

Functionality

The save step’s input and step context are used to generate the table, the list of columns and their values, which are then combined and forwarded to the database.

Example
.mongodb()
.save {
    name = "save"
    connect {
        MongoClients.create("mongodb://James23:SantaFe1987@localhost:27017")
    }
    query {
        database { _, _ ->
            "iot"
        }
        collection { _, _ ->
            "batteryState"
        }
        documents { _, input ->
            listOf(Document.parse(objectMapper.writeValueAsString(input)))
        }
    }
}
Notable parameters
  • connect (required): configures the connection to MongoDb.

  • query (required): specifies a document respecting the requirements of the target database.

Tips
  • Use the save step after a collect step in order to reduce the number of queries executed onto the database and to reduce the load your scenario generates on the test system.

  • The save step is extremely flexible; database, collection and documents may depend on the context and input value received from the previous step.

Reference Documentation

Refer to the Mongodb documentation for further parameter and configuration information.

Search step

The search step within the MongoDB plugin searches records in the database using a search query.

Ancestor

Step

Functionality

The search step’s input and step context are used to generate a document and the values to complete it; the batch of results is then forwarded to the next step(s).

Example
.search {
    name = "search"
    connect {
        MongoClients.create("mongodb://James23:SantaFe1987@localhost:27017")
    }
    search {
        database { _, _ -> "iot" }
        collection { _, _ -> "batteryState" }
        query { _, input ->
            Document(
                mapOf(
                    "deviceId" to input.deviceId,
                    "timestamp" to input.timestamp.epochSecond
                )
            )
        }
    }
}
Notable parameters
  • connect (required): configures the connection to MongoDb.

  • search (required): defines the search parameters including database, collection query and sort.

Tip

Use the search step after a collect() step in order to reduce the number of queries executed onto the database and to reduce the load the scenario generates on the test system.

Reference Documentation

Refer to the Mongodb documentation for further parameter and configuration information.