MongoDB

Databases & messaging

Drive MongoDB on the official driver: one operation per request. Install with loadr plugin install mongo.

Browse all 52 demos 12 categories
Run it
$ loadr run examples/28-mongo.yaml
examples/28-mongo.yaml
# MongoDB load test, driven by the `loadr-plugin-mongo` native protocol plugin.
#
# MongoDB support is NOT built into loadr core — it is a runtime-loadable plugin
# that ships the heavy `mongodb` Rust driver on its own. The plugin declares the
# `mongodb://` (and `mongo://`) URL scheme, so once it is installed a request to
# a `mongodb://` URL routes straight to it; no explicit `protocol:` is needed.
#
# Each request runs one operation (insert/find/update/delete/aggregate/command)
# from its `plugin:` block. loadr records the operation latency in
# `mongo_req_duration`, the count of documents inserted/matched/modified/returned
# in `mongo_docs`, and any driver error fails the request (status 0 = error,
# status 1 = ok).
#
# Build + install the plugin, then run:
#   cargo build -p loadr-plugin-mongo --release
#   mkdir -p dist && cp plugins/loadr-plugin-mongo/plugin.toml dist/ \
#     && cp target/release/libloadr_plugin_mongo.so dist/
#   loadr plugin install dist
#   loadr run examples/28-mongo.yaml
#
# Or point the plan's `plugins:` entry at the built artifact directly (below).
name: mongo
description: insert + find + aggregate against MongoDB via loadr-plugin-mongo

plugins:
  # Resolve `mongo` by name from the plugins dir (after `loadr plugin install`).
  # To run straight from a build tree instead, set:
  #   path: target/release/libloadr_plugin_mongo.so
  - name: mongo

scenarios:
  writes:
    executor: constant-vus
    vus: 5
    duration: 15s
    flow:
      - request:
          name: insert product
          url: mongodb://loadr:loadr@db.example.com:27017/loadr
          plugin:
            operation: insert
            collection: products
            document:
              name: "vu-${vu}-item"
              price: 12.5
              stock: 3
              run: "${vu}-${iteration}"
          assert:
            - { type: status, equals: 1 }            # 1 = ok, 0 = driver error

  reads:
    executor: constant-arrival-rate
    rate: 80
    duration: 15s
    pre_allocated_vus: 10
    max_vus: 40
    flow:
      - request:
          name: find cheap products
          url: mongodb://loadr:loadr@db.example.com:27017/loadr
          plugin:
            operation: find
            collection: products
            filter: { price: { $lt: 50 } }
            limit: 100
          checks:
            - { type: status, equals: 1 }
            - { type: duration, name: query is fast, max: 250ms }
      - request:
          name: aggregate stock by tag
          url: mongodb://loadr:loadr@db.example.com:27017/loadr
          plugin:
            operation: aggregate
            collection: products
            pipeline:
              - { $unwind: "$tags" }
              - { $group: { _id: "$tags", total_stock: { $sum: "$stock" } } }
              - { $sort: { total_stock: -1 } }
          checks:
            - { type: status, equals: 1 }

thresholds:
  checks: [ "rate>0.99" ]
  mongo_req_duration: [ "p(95)<300ms" ]

View raw: examples/28-mongo.yaml

What it shows

  • insert / find / update / aggregate
  • Official Mongo driver
  • Runtime plugin

Key metrics: mongo_reqs · mongo_req_duration.