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
mongo_jsonschema-0.1.2.tar.gz
(4.5 kB
view hashes)
Built Distribution
Close
Hashes for mongo_jsonschema-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9853f92684db216fbd703adfa300975dd32311da277e01842a4c6d68b63ddb07 |
|
MD5 | 6ecabee434404a38bce22fc95a413d29 |
|
BLAKE2b-256 | 2b9b7abc8d802950a1f0ee406264074fa9bf40924070763d666878b4eb1122d7 |