Giter Club home page Giter Club logo

go-mongo-indexer's Introduction

go-mongo-indexer

CLI utility to manage mongodb collection indexes

Blog URL Build Status Go Report Card

Usage

indexer --config <index-config-file> 
        --uri <mongodb-connection-uri>
        --database <database name>
        --apply

Details of options is listed below

Option Required? Description
config Yes Path to indexes configuration file
uri Yes MongoDB connection string e.g. mongodb://127.0.0.1:27017
database Yes Database name
apply No Whether to apply the indexes on collections or not. If not given, it will show the plan that will be applied

Config Format

The configuration file is just a simple json file containing the indexes to be applied. This file is an array of objects. Where each object has details like collection name, cap size and indexes for this specific collection.

[
    {
        "collection": "order",     // name of collection
        "cap": null,               // Number of bytes 
        "index": [                 // Array of index details
            {"cartId": 1},         // An ascending order index
            {"status": -1},        // Descending order index
            {"orderId": 1},
            {"groupId": 1},
            {"currency": 1},
            {"createdAt": -1},
            {"orderNumber": 1, "type": 1},  // Composite index on orderNumber and type
            {"type": -1, "paymentStatus": -1, "payment.paymentMethod": -1}
        ]
    },
    {
        "collection": "collection_name",
        "cap": null,
        "index": [
            {"userId": -1},
            {"username": 1},
            {"orderId": 1, "_unique": 1},                       // creates a `unique index`
            {"createdAt": -1, "_expireAfterSeconds": 500}       // creates a `expires index` that will delete document after given number of seconds 
        ]
    }
    ....
    ....
    ....
]

Note capping is still progress not yet supported

Examples

See list of index changes before applying

indexer --config "/path/to/xyz.json" --uri "mongodb://127.0.0.1:27017/database_name" --database "database_name"

Apply the index changes

$ indexer --config "/path/to/xyz.json" --uri "mongodb://127.0.0.1:27017/database_name"  --database "database_name" --apply

Todo

  • Write tests
  • Collection capping
  • Support for _unique and _expireAfterSeconds indexes

Contributing

Anyone is welcome to contribute, however, if you decide to get involved, please take a moment to review the guidelines:

  • Only one feature or change per pull request
  • Write meaningful commit messages
  • Follow the existing coding standards

License

MIT © Adnan Ahmed

go-mongo-indexer's People

Contributors

dependabot-preview[bot] avatar idnan avatar kamranahmedse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

go-mongo-indexer's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.