Skip to main content

Export MongoDB collection schemas into JSON Schema format

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mongo_schema_exporter-0.1.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file mongo_schema_exporter-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mongo_schema_exporter-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bcc82e759f2bb25264292cff6deabe6261c24ae15b571883fdeb256c00abeef4
MD5 b5c122bd90b14d88ea554c50e9b1c0b5
BLAKE2b-256 8b065f98963189246e1c8deace40268cbc8fe09a57ad462001473f9858add00b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page