mongo-jsonschema


Namemongo-jsonschema JSON
Version 0.1.4 PyPI version JSON
download
home_pagehttps://github.com/moseswynn/mongo-jsonschema
SummaryA CLI tool and library for reverse engineering a JSONSchema from a MongoDB database.
upload_time2024-03-27 18:21:59
maintainerNone
docs_urlNone
authorMoses Wynn
requires_python<4.0,>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Mongo Schema

Reverse engineer JSONSchemas from a MongoDB database.

## Installation

`pip install mongo-jsonschema`

## Usage

### As CLI Tool

<pre>
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.
</pre>

### As A Library

```python
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
)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/moseswynn/mongo-jsonschema",
    "name": "mongo-jsonschema",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Moses Wynn",
    "author_email": "mail@moseswynn.com",
    "download_url": "https://files.pythonhosted.org/packages/85/73/6be26af3f0df23fcaeaaa1c7e603c4a1d1a830dd1c8d268b969abbd9551c/mongo_jsonschema-0.1.4.tar.gz",
    "platform": null,
    "description": "# Mongo Schema\n\nReverse engineer JSONSchemas from a MongoDB database.\n\n## Installation\n\n`pip install mongo-jsonschema`\n\n## Usage\n\n### As CLI Tool\n\n<pre>\nusage: 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\n\nGenerates JSONSchemas from MongoDB Collections by sampling documents from the collection.\n\npositional arguments:\n  host                  A MongoDB hostname or connection string.\n  db                    The name of the database in which the collections reside.\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -c COLLECTIONS, --collections COLLECTIONS\n                        A comma separated list of collections to generate schemas from. If blank, schemas will be generated for all collections.\n  -p PORT, --port PORT  The port to use when connecting to the MongoDB server. Required if host is not a connectionstring.\n  -s SAMPLE_SIZE, --sample_size SAMPLE_SIZE\n                        A decimal representation of the percentage of total documents in the collection to sample when deriving the schema. Default is .33.\n  -r {PRIMARY,PRIMARY_PREFERRED,SECONDARY,SECONDARY_PREFERRED,NEAREST}, --read_preference {PRIMARY,PRIMARY_PREFERRED,SECONDARY,SECONDARY_PREFERRED,NEAREST}\n                        The read preference to use when querying the MongoDB database. Default is 'SECONDARY'.\n  -d DESTINATION, --destination DESTINATION\n                        The directory to output the generated schemas to. If none is specified, will be output to the current working directory.\n  -e, --external_sorting\n                        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\n                        schema will be skipped.\n</pre>\n\n### As A Library\n\n```python\nfrom mongo_jsonschema import SchemaGenerator\n\n# Initialize with your mongodb hostname and port\nschema_generator = SchemaGenerator('localhost', 27017)\n# Or use a connection string\nschema_generator = SchemaGenerator('mongodb+srv://username:password@localhost/mydatabase')\n\n#Generate schema for a multiple collections\nschemas = schema_generator.get_schemas(\n    db='mydatabase', \n    collections=['foo','bar'],\n    sample_percent=.05\n)\n\n# Generate schema for a single collection.\nschema = schema_generator.get_schemas(\n    db='dbname',\n    collection='baz',\n    sample_percent=.05\n)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A CLI tool and library for reverse engineering a JSONSchema from a MongoDB database.",
    "version": "0.1.4",
    "project_urls": {
        "Homepage": "https://github.com/moseswynn/mongo-jsonschema"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "83c29ee7852e8b7b2deb980757fdd77448c89064fa237535cdea3bc23d0ac50f",
                "md5": "5fddd68bd1b25b38ca2e2807d86ce8f8",
                "sha256": "2d36c85f38d18029db7f023df5b719b427500e8439d1afee318565a68ea2fa53"
            },
            "downloads": -1,
            "filename": "mongo_jsonschema-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5fddd68bd1b25b38ca2e2807d86ce8f8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 5760,
            "upload_time": "2024-03-27T18:21:57",
            "upload_time_iso_8601": "2024-03-27T18:21:57.998943Z",
            "url": "https://files.pythonhosted.org/packages/83/c2/9ee7852e8b7b2deb980757fdd77448c89064fa237535cdea3bc23d0ac50f/mongo_jsonschema-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "85736be26af3f0df23fcaeaaa1c7e603c4a1d1a830dd1c8d268b969abbd9551c",
                "md5": "15487332faec0da2ba185e26639dc6bd",
                "sha256": "4d3bb6a016936d4cc4f31c5d4fbcc126e546761105d00c3ccadaee768e9d86d4"
            },
            "downloads": -1,
            "filename": "mongo_jsonschema-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "15487332faec0da2ba185e26639dc6bd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 4509,
            "upload_time": "2024-03-27T18:21:59",
            "upload_time_iso_8601": "2024-03-27T18:21:59.522766Z",
            "url": "https://files.pythonhosted.org/packages/85/73/6be26af3f0df23fcaeaaa1c7e603c4a1d1a830dd1c8d268b969abbd9551c/mongo_jsonschema-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-27 18:21:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "moseswynn",
    "github_project": "mongo-jsonschema",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "mongo-jsonschema"
}
        
Elapsed time: 0.21370s