Skip to main content

MongoDB Schema Exporter

A tool to analyze MongoDB collections and generate schema definitions.

Features

  • Infers schema from MongoDB collections
  • Validate documents against generated schemas

Usage

# Basic usage
uvx mongo_schema_exporter --db your_database --collection your_collection

# Analyze multiple documents
uvx mongo_schema_exporter --db your_database --collection your_collection --limit 10

# Output as JSON Schema
uvx mongo_schema_exporter --db your_database --collection your_collection --output json

# Save output to a file
uvx mongo_schema_exporter --db your_database --collection your_collection --output json --output-file schema.json

# Connect to a remote MongoDB instance
uvx mongo_schema_exporter --uri "mongodb://user:password@hostname:port/" --db your_database --collection your_collection

# Validate documents against the generated schema
uvx mongo_schema_exporter --db your_database --collection your_collection --validate

Examples

Pretty-printed output

MongoObject(fields={
    'name': MongoField(type=MongoString(), required=True),
    'age': MongoField(type=MongoInteger(), required=False),
    'tags': MongoField(type=MongoArray(element=MongoString()), required=True),
    'metadata': MongoField(type=MongoObject(fields={
        'created': MongoField(type=MongoDate(), required=True),
        'modified': MongoField(type=MongoDate(), required=False)
    }), required=False)
})

JSON Schema output

{
  "$jsonSchema": {
    "bsonType": "object",
    "properties": {
      "name": {
        "bsonType": "string"
      },
      "age": {
        "bsonType": "int"
      },
      "tags": {
        "bsonType": "array",
        "items": {
          "bsonType": "string"
        }
      },
      "metadata": {
        "bsonType": "object",
        "properties": {
          "created": {
            "bsonType": "date"
          },
          "modified": {
            "bsonType": "date"
          }
        },
        "required": ["created"]
      }
    },
    "required": ["name", "tags"]
  }
}

License

MIT

Metadata

Release files for mongo-schema-exporter 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for mongo-schema-exporter 0.1.3
File Interpreter ABI Platform
mongo_schema_exporter-0.1.3-py3-none-any.whl Python 3 none any Details

Release files / mongo_schema_exporter-0.1.3-py3-none-any.whl

Download URL mongo_schema_exporter-0.1.3-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed4766e7f638dd15870a901a054845d2601649c55cc3368906be2d766c175d93
BLAKE2b-256 checksum
How to use checksums
c317132413a5e0bb77b3359a6002296fe95064ee09a083139f746466ef08d068
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

0.1.3 This release

1 release file

0.1.2

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page