Connect to a MongoDB database to inspect its schema (databases, collections, indexes, document structure) and execute read-only queries (find, aggregate). Use when the user needs to explore or retrieve data from a MongoDB database.
Inspect schemas and run read-only queries against a MongoDB database using the bundled helper script.
Before first use, ensure the pymongo Python package is installed:
pip install pymongo
${CLAUDE_SKILL_DIR}/scripts/query_mongodb.py
| Argument | Env Variable | Default | Description |
|---|---|---|---|
--uri |
MONGO_URI |
mongodb://localhost:27017 |
| MongoDB connection URI |
--host | MONGO_HOST | localhost | Database host (if no URI) |
--port | MONGO_PORT | 27017 | Database port (if no URI) |
--database | MONGO_DATABASE | (none) | Database name |
--user | MONGO_USER | (none) | Username (if no URI) |
--password | MONGO_PASSWORD | (none) | Password (if no URI) |
--auth-db | MONGO_AUTH_DB | admin | Authentication database |
Ask the user for connection details before running the script. Never guess or assume credentials.
List all databases:
python3 ${CLAUDE_SKILL_DIR}/scripts/query_mongodb.py --uri <uri> schema --list-databases
List all collections in a database:
python3 ${CLAUDE_SKILL_DIR}/scripts/query_mongodb.py --uri <uri> --database <db> schema
Inspect a specific collection (indexes + inferred document structure from a sample):
python3 ${CLAUDE_SKILL_DIR}/scripts/query_mongodb.py --uri <uri> --database <db> schema --collection <collection>
Run a find() with an optional filter, projection, sort, and limit:
python3 ${CLAUDE_SKILL_DIR}/scripts/query_mongodb.py --uri <uri> --database <db> find <collection> --filter '{"status": "active"}' --projection '{"name": 1, "email": 1}' --sort '{"created_at": -1}' --limit 10
If no filter is provided, returns all documents (up to the limit):
python3 ${CLAUDE_SKILL_DIR}/scripts/query_mongodb.py --uri <uri> --database <db> find <collection>
Run an aggregation pipeline:
python3 ${CLAUDE_SKILL_DIR}/scripts/query_mongodb.py --uri <uri> --database <db> aggregate <collection> --pipeline '[{"$match": {"status": "active"}}, {"$group": {"_id": "$category", "count": {"$sum": 1}}}]'
readPreference=secondaryPreferred.find, aggregate, schema inspection). No write methods (insert, update, delete) are available.--limit <N> to change this.--limit to avoid returning excessively large result sets.p%40ss for p@ss).