Skip to main content

MongoDB Index migration tool

Project description

mongodex

Mongodex is a Python library to migrate your MongoDB database indexes.

Installation

pip install mongodex

How to use

To migrate your indexes to a MongoDB database, you need to create a dictionary that contains each collection index. The indexes must be a mongodex.Index instance. For example:

from pymongo import ASCENDING, DESCENDING
import mongodex

collections = {
    "<COLLECTION_NAME>": [
        mongodex.Index({"<FIELD_NAME>": ASCENDING}, unique=True),
        mongodex.Index({"<FIELD_NAME>": ASCENDING, "<FIELD_NAME>": ASCENDING}),
    ],
    "<COLLECTION_NAME>": [
        mongodex.Index({"<FIELD_NAME>": DESCENDING}, name="custom_index_name"),
    ]
}

Then you can migrate your indexes by calling the mongodex.migrate function with your database URI.

mongodex.migrate("<DATABASE_URI>", collections)

Markdown docs generator

You can also create a markdown file with all your indexes using the same collection index dictionary mentioned in the previous topic. For example:

mongodex.md_generator(collections)

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

mongodex-0.0.1.tar.gz (5.1 kB view hashes)

Uploaded Source

Built Distribution

mongodex-0.0.1-py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page