CLI tool to manage mongo database collection indexes through json files
$ indexer --config <json config file> --uri <mongo database uri>
Below is the description of all the accepted options
--apply
not required, to apply the index changes--config
required, path to json file containing the each collection index. This json file should be in this format--uri
required, mongo database uri
The config json file that you will pass to --config
flag to index the database collection should be in specific format. This file is an array of objects. Where each object has details like collection name, cap size and indexes for this specific collection.
[
{
"collection": "collection_name",
"cap": null,
"index": [
["cartId"],
["-status"],
["orderId"],
["groupId"],
["currency"]
["-createdAt"],
["orderNumber", "type"],
["-type", "-paymentStatus", "-payment.paymentMethod"],
]
},
{
"collection": "collection_name",
"cap": null,
"index": [
["-userId"]
["username"],
["-createdAt", "-user.email"],
]
}
....
....
....
]
Collection
is the collection namecap
collection cap size in bytes (not yet supported)index
array of indexes-
sign before a column refers to the descending order and no sign before column name refers to the ascending order
See list of index changes before applying
$ indexer --config "/path/to/xyz.json" --uri "mongodb://127.0.0.1:27017/database_name"
Apply the index changes
$ indexer --config "/path/to/xyz.json" --uri "mongodb://127.0.0.1:27017/database_name" --apply
- write tests
- cap on collection
- support for
unique
andexpireAt
indexes
MIT © Adnan Ahmed