Works with BSON (binary JSON) data: conversion with bsondump, mongoexport/mongorestore round-trips, and Python bson handling.
Agentic Workflow: Read -> Reason -> Act (bson)
You are Bson (api/general) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — api context for bson
- Domain: Works with BSON (binary JSON) data: conversion with bsondump, mongoexport/mongorestore round-trips, and Python bson handling.
- bsondump: Convert BSON files to JSON for inspection. —
bsondump file.bson
- mongo-tools: Export/import BSON with mongo tools. —
mongoexport --collection=users --out=users.bson --uri mongodb://localhost:27017/
- python-bson: Encode/decode BSON with pymongo's bson module. —
pip install pymongo
- Check
knowledge and prerequisites: bsondump, mongodump, mongoexport, mongorestore
2. Reason — think for bson
- For
bsondump: Convert BSON files to JSON for inspection. — decide which checks to run
- For
mongo-tools: Export/import BSON with mongo tools. — decide which checks to run
- For
python-bson: Encode/decode BSON with pymongo's bson module. — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with bson tools
- Tools:
Glob, Grep, Read, Bsondump, Mongoexport (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
bson:c73b62d4
BSON
What this skill does
Works with BSON data: converting BSON files to JSON with bsondump, exporting/importing with mongo tools, and encoding/decoding with Python's bson module.
When to use
- Inspecting MongoDB dump files without a server
- Round-tripping data between clusters
- Handling BSON binary fields (ObjectId, dates) in scripts
Real commands
# Inspect a BSON file
bsondump --pretty dump.bson | head -20
# Convert to JSON
bsondump --type=json collection.bson > collection.json
# Dump a database to archive
mongodump --uri mongodb://localhost:27017/app --archive=dump.bson
# Restore
mongorestore --drop --archive=dump.bson --uri mongodb://localhost:27017/app
# Python
python -c "from bson import BSON; d=BSON.encode({'hello': 'world'}); print(d.hex()); print(BSON.decode(d))"
Testing
- Round-trip: decode a file, re-encode, and diff documents
- Verify ObjectId and ISODate fields survive conversion
Best practices
- Use mongodump --archive for consistent snapshots
- Keep BSON sizes small: prefer compact field names
- Use json_util for JSON interop with extended types
Capabilities
bsondump
Convert BSON files to JSON for inspection.
Parameters:
file (string): BSON file path
type (string): Output type: json or debug
Commands:
bsondump file.bson
bsondump --pretty file.bson
bsondump --type=json file.bson > file.json
bsondump --quiet file.bson
Examples:
- bsondump --pretty dump.bson | head -20
- bsondump --type=json collection.bson > collection.json
- bsondump file.bson | jq .
mongo-tools
Export/import BSON with mongo tools.
Parameters:
collection (string): Collection name
uri (string): MongoDB connection URI
archive (string): Archive file
Commands:
mongoexport --collection=users --out=users.bson --uri mongodb://localhost:27017/app
mongoexport --collection=users --out=users.json --uri mongodb://localhost:27017/app
mongorestore --archive=users.bson --uri mongodb://localhost:27017/app
mongorestore --drop --archive=dump.bson --uri mongodb://localhost:27017/app
mongodump --uri mongodb://localhost:27017/app --archive=dump.bson
Examples:
- mongodump --uri mongodb://localhost:27017/app --archive=dump.bson
- mongoexport --collection=orders --out=orders.bson --uri mongodb://localhost:27017/app --query '{"status":"paid"}'
- mongorestore --drop --archive=dump.bson --uri mongodb://localhost:27017/app
python-bson
Encode/decode BSON with pymongo's bson module.
Parameters:
document (string): Python dict to encode
Commands:
pip install pymongo
python -c "from bson import BSON; d=BSON.encode({'a': 1, 'b': 'x'}); print(d.hex())"
python -c "from bson import BSON; d=BSON.encode({'a': 1}); print(BSON.decode(d))"
python -c "from bson import encode; print(encode({'ts': __import__('datetime').datetime.now()}).hex())"
Examples:
- python -c "from bson import BSON; d=BSON.encode({'hello': 'world'}); print(d.hex()); print(BSON.decode(d))"
- python -c "from bson import json_util; print(json_util.dumps({'ts': import('datetime').datetime.utcnow()}))"
- python -c "from bson import ObjectId; print(ObjectId())"
References
1---2name: "bson"3description: "Works with BSON (binary JSON) data: conversion with bsondump, mongoexport/mongorestore round-trips, and Python bson handling. Use when working with bsondump, mongo tools, python bson, api or when the user mentions bsondump, mongo tools, python bson, api."4license: "MIT"5compatibility: "Requires bsondump, mongodump, mongoexport, mongorestore, pip, python."6metadata:7 source: https://skillmd.com/skills/opknock/bson8 author: Kdesk9 version: 2.0.010 category: api11allowed-tools: "Glob Grep Read Bash(bsondump:*) Bash(mongodump:*) Bash(mongoexport:*) Bash(mongorestore:*) Bash(pip:*) Bash(python:*)"12---1314Works with BSON (binary JSON) data: conversion with bsondump, mongoexport/mongorestore round-trips, and Python bson handling.1516## Agentic Workflow: Read -> Reason -> Act (bson)1718You are **Bson** (api/general) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — api context for `bson`21- Domain: Works with BSON (binary JSON) data: conversion with bsondump, mongoexport/mongorestore round-trips, and Python bson handling.22- **bsondump**: Convert BSON files to JSON for inspection. — `bsondump file.bson`23- **mongo-tools**: Export/import BSON with mongo tools. — `mongoexport --collection=users --out=users.bson --uri mongodb://localhost:27017/`24- **python-bson**: Encode/decode BSON with pymongo's bson module. — `pip install pymongo`25- Check `knowledge` and `prerequisites: bsondump, mongodump, mongoexport, mongorestore`2627### 2. Reason — think for `bson`28- For `bsondump`: Convert BSON files to JSON for inspection. — decide which checks to run29- For `mongo-tools`: Export/import BSON with mongo tools. — decide which checks to run30- For `python-bson`: Encode/decode BSON with pymongo's bson module. — decide which checks to run31- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3233### 3. Act — execute with `bson` tools34- Tools: `Glob`, `Grep`, `Read`, `Bsondump`, `Mongoexport` (see frontmatter `tools`/`allowed-tools`)35- Use `safe_path` for any write; record evidence (paths, checksums)36- Fingerprint: `bson:c73b62d4`3738# BSON3940## What this skill does4142Works with BSON data: converting BSON files to JSON with bsondump, exporting/importing with mongo tools, and encoding/decoding with Python's bson module.4344## When to use4546- Inspecting MongoDB dump files without a server47- Round-tripping data between clusters48- Handling BSON binary fields (ObjectId, dates) in scripts4950## Real commands5152```bash53# Inspect a BSON file54bsondump --pretty dump.bson | head -205556# Convert to JSON57bsondump --type=json collection.bson > collection.json5859# Dump a database to archive60mongodump --uri mongodb://localhost:27017/app --archive=dump.bson6162# Restore63mongorestore --drop --archive=dump.bson --uri mongodb://localhost:27017/app6465# Python66python -c "from bson import BSON; d=BSON.encode({'hello': 'world'}); print(d.hex()); print(BSON.decode(d))"67```6869## Testing7071- Round-trip: decode a file, re-encode, and diff documents72- Verify ObjectId and ISODate fields survive conversion7374## Best practices7576- Use mongodump --archive for consistent snapshots77- Keep BSON sizes small: prefer compact field names78- Use json_util for JSON interop with extended types7980## Capabilities8182### bsondump83Convert BSON files to JSON for inspection.8485**Parameters:**86- `file` (string): BSON file path87- `type` (string): Output type: json or debug8889**Commands:**90- `bsondump file.bson`91- `bsondump --pretty file.bson`92- `bsondump --type=json file.bson > file.json`93- `bsondump --quiet file.bson`9495**Examples:**96- bsondump --pretty dump.bson | head -2097- bsondump --type=json collection.bson > collection.json98- bsondump file.bson | jq .99100### mongo-tools101Export/import BSON with mongo tools.102103**Parameters:**104- `collection` (string): Collection name105- `uri` (string): MongoDB connection URI106- `archive` (string): Archive file107108**Commands:**109- `mongoexport --collection=users --out=users.bson --uri mongodb://localhost:27017/app`110- `mongoexport --collection=users --out=users.json --uri mongodb://localhost:27017/app`111- `mongorestore --archive=users.bson --uri mongodb://localhost:27017/app`112- `mongorestore --drop --archive=dump.bson --uri mongodb://localhost:27017/app`113- `mongodump --uri mongodb://localhost:27017/app --archive=dump.bson`114115**Examples:**116- mongodump --uri mongodb://localhost:27017/app --archive=dump.bson117- mongoexport --collection=orders --out=orders.bson --uri mongodb://localhost:27017/app --query '{"status":"paid"}'118- mongorestore --drop --archive=dump.bson --uri mongodb://localhost:27017/app119120### python-bson121Encode/decode BSON with pymongo's bson module.122123**Parameters:**124- `document` (string): Python dict to encode125126**Commands:**127- `pip install pymongo`128- `python -c "from bson import BSON; d=BSON.encode({'a': 1, 'b': 'x'}); print(d.hex())"`129- `python -c "from bson import BSON; d=BSON.encode({'a': 1}); print(BSON.decode(d))"`130- `python -c "from bson import encode; print(encode({'ts': __import__('datetime').datetime.now()}).hex())"`131132**Examples:**133- python -c "from bson import BSON; d=BSON.encode({'hello': 'world'}); print(d.hex()); print(BSON.decode(d))"134- python -c "from bson import json_util; print(json_util.dumps({'ts': __import__('datetime').datetime.utcnow()}))"135- python -c "from bson import ObjectId; print(ObjectId())"136137## References138- [bsondump Reference](https://www.mongodb.com/docs/database-tools/bsondump/)139- [BSON Specification](https://bsonspec.org/)140- [MongoDB Database Tools](https://www.mongodb.com/docs/database-tools/)