{"id":15654574,"url":"https://github.com/jonnoftw/mongo-schema-export","last_synced_at":"2025-05-01T02:47:12.364Z","repository":{"id":51260962,"uuid":"141527633","full_name":"JonnoFTW/mongo-schema-export","owner":"JonnoFTW","description":"Simple tool to clone metadata for mongodb collections","archived":false,"fork":false,"pushed_at":"2022-09-14T11:58:29.000Z","size":13,"stargazers_count":32,"open_issues_count":2,"forks_count":14,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-25T12:23:17.364Z","etag":null,"topics":["import-and-export","metadata","mongodb","pymongo"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JonnoFTW.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-19T05:15:40.000Z","updated_at":"2024-11-11T08:01:53.000Z","dependencies_parsed_at":"2023-01-18T07:15:27.743Z","dependency_job_id":null,"html_url":"https://github.com/JonnoFTW/mongo-schema-export","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonnoFTW%2Fmongo-schema-export","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonnoFTW%2Fmongo-schema-export/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonnoFTW%2Fmongo-schema-export/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonnoFTW%2Fmongo-schema-export/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JonnoFTW","download_url":"https://codeload.github.com/JonnoFTW/mongo-schema-export/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242728412,"owners_count":20175935,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["import-and-export","metadata","mongodb","pymongo"],"created_at":"2024-10-03T12:52:34.391Z","updated_at":"2025-03-09T17:30:45.559Z","avatar_url":"https://github.com/JonnoFTW.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Import/Export Mongo Schema\n===================\nImport and export mongodb schemas **without** copying all the data. It will extract the following meta data about a mongo database:\n\n* Collections\n* Indexes\n* Cap sizes\n* Schema validators\n\nThe primary use case is when you have developed an application that uses mongodb, and want to setup a new instance with\nthe appopriate database layout. You can then provide a `config.json` file with your application and have this script\nsetup the database for you without the need for extra `ensureIndex` calls!\n\nThis data will be stored in a `json` file for a database that looks something like this:\n\n```json\n{\n    \"databases\": {\n        \"test\": {\n            \"location\": {\n                \"indexes\": [\n                    {\n                        \"name\": \"_id_\",\n                        \"keys\": [\n                            [\n                                \"_id\",\n                                1\n                            ]\n                        ]\n                    },\n                    {\n                        \"name\": \"pos_2dsphere\",\n                        \"2dsphereIndexVersion\": 3,\n                        \"keys\": [\n                            [\n                                \"pos\",\n                                \"2dsphere\"\n                            ]\n                        ]\n                    },\n                    {\n                        \"name\": \"device_1_timestamp_1\",\n                        \"keys\": [\n                            [\n                                \"device\",\n                                1\n                            ],\n                            [\n                                \"timestamp\",\n                                1\n                            ]\n                        ]\n                    }\n                ],\n                \"options\": {}\n            },\n            \"users\": {\n                \"indexes\": [\n                    {\n                        \"name\": \"_id_\",\n                        \"keys\": [\n                            [\n                                \"_id\",\n                                1\n                            ]\n                        ]\n                    },\n                    {\n                        \"unique\": true,\n                        \"name\": \"username_idx\",\n                        \"keys\": [\n                            [\n                                \"username\",\n                                1\n                            ]\n                        ]\n                    }\n                ],\n                \"options\": {\n                    \"validator\": {\n                        \"$jsonSchema\": {\n                            \"bsonType\": \"object\",\n                            \"required\": [\n                                \"username\",\n                                \"password\",\n                                \"level\"\n                            ],\n                            \"properties\": {\n                                \"username\": {\n                                    \"bsonType\": \"string\",\n                                    \"description\": \"must be a string and is required\"\n                                },\n                                \"level\": {\n                                    \"bsonType\": \"string\",\n                                    \"enum\": [\n                                        \"user\",\n                                        \"admin\",\n                                        \"moderator\"\n                                    ],\n                                    \"description\": \"must be a string\"\n                                },\n                                \"password\": {\n                                    \"bsonType\": \"string\",\n                                    \"description\": \"must be a bcrypt password\",\n                                    \"pattern\": \"^\\\\$2b\\\\$\\\\d{1,2}\\\\$[A-Za-z0-9\\\\.\\\\/]{53}$\"\n                                }\n                            }\n                        }\n                    },\n                    \"validationLevel\": \"strict\",\n                    \"validationAction\": \"error\"\n                }\n            },\n            \"capped\": {\n                \"indexes\": [\n                    {\n                        \"name\": \"_id_\",\n                        \"keys\": [\n                            [\n                                \"_id\",\n                                1\n                            ]\n                        ]\n                    },\n                    {\n                        \"unique\": true,\n                        \"name\": \"key_1\",\n                        \"keys\": [\n                            [\n                                \"key\",\n                                1\n                            ]\n                        ]\n                    }\n                ],\n                \"options\": {\n                    \"capped\": true,\n                    \"size\": 64000,\n                    \"max\": 5000,\n                    \"validator\": {\n                        \"$jsonSchema\": {\n                            \"bsonType\": \"object\",\n                            \"description\": \"Simple key value store\",\n                            \"required\": [\n                                \"key\",\n                                \"value\"\n                            ],\n                            \"properties\": {\n                                \"key\": {\n                                    \"bsonType\": \"string\",\n                                    \"maxLength\": 64.0,\n                                    \"description\": \"the key value\"\n                                },\n                                \"value\": {\n                                    \"bsonType\": \"string\",\n                                    \"description\": \"the associated value\"\n                                }\n                            }\n                        }\n                    },\n                    \"validationLevel\": \"strict\",\n                    \"validationAction\": \"error\"\n                }\n            }\n        }\n    },\n    \"exported\": \"2018-07-18T17:12:43.460992\"\n}\n```\n\nInstallation\n------------\n\n```bash\npip install MongoSchemaImportExport\n```\n\nUsage\n-----\nMake sure the user you are using to import/export has the appropriate privileges, they'll probably need to have the\n `root` role or `dbOwner` on the source and destination.\nTo export your data run:\n\n```bash\nmongo-schema-export.py --uri mongodb://user:password@database.host1.com:27017/admin --databases test2,testIgnore\n```\n\nTo import your schema run as bellow. Use `--delete-col` to delete collections before creating them (**WARNING:** this\n will delete your data, you cannot change \nan existing collection into a capped one, although, you can set a validator after creation):\n\n```bash\nmongo-schema-import.py --uri mongodb://user:password@database.host2.com:27017/admin --databases db_1,db_2 --verbose --delete-col\n```\nYou will get an output like this:\n\n```\nSkipping: testIgnore\nCreating database: test2\n\tDropping collection location\n\tCreating collection: location\n\t\tOptions {}\n\t\tCreating index: {'name': '_id_', 'keys': [['_id', 1]]}\n\t\tCreating index: {'name': 'pos_2dsphere', '2dsphereIndexVersion': 3, 'keys': [['pos', '2dsphere']]}\n\t\tCreating index: {'name': 'device_1_timestamp_1', 'keys': [['device', 1], ['timestamp', 1]]}\n\tDropping collection users\n\tCreating collection: users\n\t\tOptions {'validator': {'$jsonSchema': {'bsonType': 'object', 'required': ['username', 'password', 'level'], 'properties': {'username': {'bsonType': 'string', 'description': 'must be a string and is required'}, 'level': {'bsonType': 'string', 'enum': ['user', 'admin', 'moderator'], 'description': 'must be a string'}, 'password': {'bsonType': 'string', 'description': 'must be a bcrypt password', 'pattern': '^\\\\$2b\\\\$\\\\d{1,2}\\\\$[A-Za-z0-9\\\\.\\\\/]{53}$'}}}}, 'validationLevel': 'strict', 'validationAction': 'error'}\n\t\tCreating index: {'name': '_id_', 'keys': [['_id', 1]]}\n\t\tCreating index: {'unique': True, 'name': 'username_idx', 'keys': [['username', 1]]}\n\tDropping collection capped\n\tCreating collection: capped\n\t\tOptions {'capped': True, 'size': 64000, 'max': 5000, 'validator': {'$jsonSchema': {'bsonType': 'object', 'description': 'Simple key value store', 'required': ['key', 'value'], 'properties': {'key': {'bsonType': 'string', 'maxLength': 64.0, 'description': 'the key value'}, 'value': {'bsonType': 'string', 'description': 'the associated value'}}}}, 'validationLevel': 'strict', 'validationAction': 'error'}\n\t\tCreating index: {'name': '_id_', 'keys': [['_id', 1]]}\n\t\tCreating index: {'unique': True, 'name': 'key_1', 'keys': [['key', 1]]}\n\n```\n\n\nIf you get permission errors, make sure your user has the right roles to read and write databases and collections.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonnoftw%2Fmongo-schema-export","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonnoftw%2Fmongo-schema-export","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonnoftw%2Fmongo-schema-export/lists"}