A CLI tool and library for reverse engineering a JSONSchema from a MongoDB database.
Project description
Mongo Schema
Reverse engineer JSONSchemas from a MongoDB database.
Installation
pip install mongo-jsonschema
Usage
As CLI Tool
usage: python -m mongo_jsonschema [-h] [-c COLLECTIONS] [-p PORT] [-s SAMPLE_SIZE] [-r {PRIMARY,PRIMARY_PREFERRED,SECONDARY,SECONDARY_PREFERRED,NEAREST}] [-d DESTINATION] [-e] host db
Generates JSONSchemas from MongoDB Collections by sampling documents from the collection.
positional arguments:
host A MongoDB hostname or connection string.
db The name of the database in which the collections reside.
optional arguments:
-h, --help show this help message and exit
-c COLLECTIONS, --collections COLLECTIONS
A comma separated list of collections to generate schemas from. If blank, schemas will be generated for all collections.
-p PORT, --port PORT The port to use when connecting to the MongoDB server. Required if host is not a connectionstring.
-s SAMPLE_SIZE, --sample_size SAMPLE_SIZE
A decimal representation of the percentage of total documents in the collection to sample when deriving the schema. Default is .33.
-r {PRIMARY,PRIMARY_PREFERRED,SECONDARY,SECONDARY_PREFERRED,NEAREST}, --read_preference {PRIMARY,PRIMARY_PREFERRED,SECONDARY,SECONDARY_PREFERRED,NEAREST}
The read preference to use when querying the MongoDB database. Default is 'SECONDARY'.
-d DESTINATION, --destination DESTINATION
The directory to output the generated schemas to. If none is specified, will be output to the current working directory.
-e, --external_sorting
Enables external sorting, using the disk on the mongodb server, for aggregations that exceed the memory limit. If false, the aggregation fails due to an exceeded memory limit, the
schema will be skipped.
As A Library
from mongo_jsonschema import SchemaGenerator
# Initialize with your mongodb hostname and port
schema_generator = SchemaGenerator('localhost', 27017)
# Or use a connection string
schema_generator = SchemaGenerator('mongodb+srv://username:password@localhost/mydatabase')
#Generate schema for a multiple collections
schemas = schema_generator.get_schemas(
db='mydatabase',
collections=['foo','bar'],
sample_percent=.05
)
# Generate schema for a single collection.
schema = schema_generator.get_schemas(
db='dbname',
collection='baz',
sample_percent=.05
)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mongo_jsonschema-0.1.4.tar.gz.
File metadata
- Download URL: mongo_jsonschema-0.1.4.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.10.6 Darwin/23.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d3bb6a016936d4cc4f31c5d4fbcc126e546761105d00c3ccadaee768e9d86d4
|
|
| MD5 |
15487332faec0da2ba185e26639dc6bd
|
|
| BLAKE2b-256 |
85736be26af3f0df23fcaeaaa1c7e603c4a1d1a830dd1c8d268b969abbd9551c
|
File details
Details for the file mongo_jsonschema-0.1.4-py3-none-any.whl.
File metadata
- Download URL: mongo_jsonschema-0.1.4-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.10.6 Darwin/23.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d36c85f38d18029db7f023df5b719b427500e8439d1afee318565a68ea2fa53
|
|
| MD5 |
5fddd68bd1b25b38ca2e2807d86ce8f8
|
|
| BLAKE2b-256 |
83c29ee7852e8b7b2deb980757fdd77448c89064fa237535cdea3bc23d0ac50f
|