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.2-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for mongo_schema_exporter-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dea4808fede3038ef7699808f6bccabdc7e7ccf86fc47fbeb2d9758aae6a72c9
MD5 d3cf96346e5c05f5e3e4e7e706a07186
BLAKE2b-256 a79177e396df43fa726759cf4f26ef783b25bdcc6b8c6c3b84201389fcc417c9

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