https://github.com/nimeshkverma/mongo_schema
Python Package to provide a rough schema for the mongodb collection
https://github.com/nimeshkverma/mongo_schema
mongodb-collections mongoschema pip python schema schema-information stats
Last synced: 13 days ago
JSON representation
Python Package to provide a rough schema for the mongodb collection
- Host: GitHub
- URL: https://github.com/nimeshkverma/mongo_schema
- Owner: nimeshkverma
- License: mit
- Created: 2015-09-22T16:44:15.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-04-12T10:17:12.000Z (about 5 years ago)
- Last Synced: 2025-04-08T14:45:50.105Z (about 1 month ago)
- Topics: mongodb-collections, mongoschema, pip, python, schema, schema-information, stats
- Language: Python
- Size: 25.4 KB
- Stars: 12
- Watchers: 4
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# mongoschema
**MongoDB schema information in Python****mongoschema** is a library written in Python to provide concise description of the schema of a collection in MongoDB
## Installation
***
To install the package, type the following -pip install mongoschema
## Sample data - Populating MongoDB with sample data
***
Navigate to `test/sample_data` in the `mongojoin` directory and type the following command -> mongoimport --dbname test --collection supplier --file supplier.json
> mongoimport --dbname test --collection order --file order.jsonThis will create and populate the required collections with sample data.
The two collections *supplier* and *order* will be used to demonstrate how to use **mongoschema**.
To check the contents of the collection, the following command can be used in the MongoDB shell :> use test
> db.supplier.find({})
> db.order.find({})## Using `mongoschema` to get the schema information of a MongoDB collections
***
Type the following in Python shell to import `mongoschema`->>> from mongoschema import Schema
To create a `Schema` object for the collection to be analysed, type the following -
>>> schema = Schema("test", "supplier")
where `test` is the DB name and `supplier` is the Collection name.
Additional parameters -
`host` : Mongo uri (String)
`port` : Port Number (Integer)
`limit`: Number of docs to be sampledTo get the stats of the collection -
>>> num_docs, result = schema.get_schema()
`num_docs`: Total number of docs sampled
`result` : Dictionary containing the statsUse the following command to pretty print the results -
>>> schema.print_schema()
+-------------+------------------+-----------------------+------------------+-----------------------+
| Key | Occurrence Count | Occurrence Percentage | Value Type | Value Type Percentage |
+-------------+------------------+-----------------------+------------------+-----------------------+
| supplier_id | 7 | 100.0 | | 100.0 |
| name | 7 | 100.0 | | 100.0 |
| _id | 7 | 100.0 | other | 100.0 |
+-------------+------------------+-----------------------+------------------+-----------------------+More contents here - https://pypi.python.org/pypi/mongoschema/