You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

mongo-schema-exporter

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongo-schema-exporter

Export MongoDB collection schemas into JSON Schema format

0.1.3
PyPI
Maintainers
1

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

Keywords

database

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts