0:29

🧩 / MongoDB / Query

KindDescriptionPricing
UnitExecute scripts with the MongoDB ShellFREE

Introduction

This Docker image includes the MongoDB Shell, use it to query a MongoDB database inside a Kubirds unit.

Usage

Environment

VariableDefaultDescription
DATABASE_URLN/AMongoDB connection URL to your database
MONGO_SCRIPTS_DIRN/APath to the volume containing your scripts (ending with .js or .mongodb)

Example of Unit

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: my-mongo-scripts
data:
  getUserCount.js: |
    db = db.getSiblingDB("admin");
    printjson(db.system.users.countDocuments());    

---
apiVersion: kubirds.com/v1
kind: Unit
metadata:
  name: get-mongo-usercount
spec:
  schedule: every 5 minutes
  image:
    name: linksociety/kubirds-unit-mongosh:latest
    pullPolicy: Always
    command: run-mongo-scripts
  env:
    - name: DATABASE_URL
      valueFrom:
        secretKeyRef:
          name: mongodb-access
          key: URL
    - name: MONGO_SCRIPTS_DIR
      value: /scripts
  volumes:
    - name: mongo-scripts
      mountPath: /scripts
      configMap:
        name: my-mongo-scripts