← 返回
未分类 Key 中文

mongodb-query

Query MongoDB databases for debugging and troubleshooting. Use when user needs to: (1) List all databases, (2) List collections in a database, (3) Execute Mo...
用于调试和故障排查,查询MongoDB数据库。用户需要时可以: (1) 列出所有数据库; (2) 列出数据库中的集合; (3) 执行MongoDB查询或命令。
peintune peintune 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 需要
★ 0
Stars
📥 336
下载
💾 0
安装
1
版本
#latest

概述

MongoDB Query

Query MongoDB with automatic connection handling (direct IP or Kubernetes port-forward).

Prerequisites

Dependencies:

  • Python 3.6+
  • pymongo package: pip install pymongo
  • kubectl (only needed if connecting to Kubernetes service via port-forward)

The agent MUST ask user for MongoDB connection information before using this skill.

Required information:

  1. MongoDB Connection String (required): Full connection URI including credentials
    • Example: mongodb://root:password@172.16.79.249:27017/?authSource=admin&replicaSet=rs0
    • Example for K8s: mongodb://root:password@mongodb.mongodb.svc.cluster.local:27017/?authSource=admin
  1. Kubernetes Namespace (optional): Only needed if the MongoDB address is a Kubernetes service name

Recommendation: Save connection info to project's TOOLS.md for future reference:

### MongoDB

- mongo_conn_str: mongodb://user:pass@host:port/?options
- mongo_namespace: (optional - only if K8s service name)

Connection Mode

The script automatically detects connection type based on the host in connection URI:

Address TypeConnection Method
---------------------------------
IP address (e.g., 172.16.79.249:27017)Direct connection
K8s Service (e.g., mongodb.mongodb.svc.cluster.local:27017)kubectl port-forward

Usage

# List all databases
python scripts/query_mongo.py --uri "mongodb://user:pass@host:27017/?authSource=admin" --list-dbs

# List collections in a database
python scripts/query_mongo.py --uri "mongodb://user:pass@host:27017/?authSource=admin" --db <database> --list-collections

# Execute a query
python scripts/query_mongo.py --uri "mongodb://user:pass@host:27017/?authSource=admin" --db <database> --collection <name> --query '{"status": "active"}'

# For K8s service names, specify namespace
python scripts/query_mongo.py --uri "mongodb://user:pass@svc.ns.svc.cluster.local:27017/?authSource=admin" --list-dbs --namespace mongodb

Parameters

ParameterDescriptionRequired
----------------------------------
--uriMongoDB connection stringYes
--list-dbsList all databasesNo
--db Database nameFor collection/query operations
--list-collectionsList all collections in databaseNo
--collection Collection nameFor query operations
--query MongoDB query in JSON formatNo
--namespace Kubernetes namespace (required if host is a K8s service name)Conditional
--limit Limit number of results (default: 10)No
--jsonOutput raw JSONNo

Examples

# List all databases
python scripts/query_mongo.py --uri "mongodb://root:pass@172.16.79.249:27017/?authSource=admin" --list-dbs

# Find active users
python scripts/query_mongo.py --uri "mongodb://root:pass@172.16.79.249:27017/?authSource=admin" --db production --collection users --query '{"status": "active"}'

# Query by ObjectId
python scripts/query_mongo.py --uri "mongodb://root:pass@172.16.79.249:27017/?authSource=admin" --db production --collection users --query '{"_id": {"$oid": "507f1f77bcf86cd799439011"}}'

# Limit results
python scripts/query_mongo.py --uri "mongodb://root:pass@172.16.79.249:27017/?authSource=admin" --db production --collection logs --query '{"level": "ERROR"}' --limit 20

# K8s service mode
python scripts/query_mongo.py --uri "mongodb://root:pass@mongodb.mongodb.svc.cluster.local:27017/?authSource=admin" --db production --collection users --query '{}' --namespace mongodb

Output

  • List operations: Returns database/collection names
  • Query operations: Returns matching documents in formatted or JSON format

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-07 19:50 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

it-ops-security

MoltGuard - Security & Antivirus & Guardrails

thomaslwang
MoltGuard — OpenClaw 安全守卫,由 OpenGuardrails 提供。安装后可防止您和您的用户受到提示注入、数据泄露及恶意行为的侵害。
★ 116 📥 31,029
it-ops-security

Free Ride - Unlimited free AI

shaivpidadi
管理OpenClaw的OpenRouter免费AI模型,自动按质量排名模型,配置速率限制备用方案,并更新opencla...
★ 472 📥 78,659
it-ops-security

1password

steipete
设置和使用 1Password CLI (op)。适用于:安装 CLI、启用桌面应用集成、登录(单/多账户)、通过 op 读取/注入/运行密钥。
★ 53 📥 31,808