|
3 | 3 |
|
4 | 4 | ## Usage
|
5 | 5 | ```shell
|
6 |
| -$ index --config <json config file> --uri <mongo database uri> |
| 6 | +$ indexer --config <json config file> --uri <mongo database uri> |
7 | 7 | ```
|
8 | 8 | Below is the description of all the accepted options
|
9 | 9 | - `--apply` not required, to apply the index changes
|
10 |
| -- `--config` required, path to json file containing the each collection index |
| 10 | +- `--config` required, path to json file containing the each collection index. This json file should be in this [format](https://gist.github.com/Idnan/71e0478985a3aefa88f6502f83b28056#file-go-mongo-indexer-format-json) |
11 | 11 | - `--uri` required, mongo database uri
|
12 | 12 |
|
| 13 | +## Json Format |
| 14 | +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. |
| 15 | +``` |
| 16 | +[ |
| 17 | + { |
| 18 | + "collection": "collection_name", |
| 19 | + "cap": null, |
| 20 | + "index": [ |
| 21 | + ["cartId"], |
| 22 | + ["-status"], |
| 23 | + ["orderId"], |
| 24 | + ["groupId"], |
| 25 | + ["currency"] |
| 26 | + ["-createdAt"], |
| 27 | + ["orderNumber", "type"], |
| 28 | + ["-type", "-paymentStatus", "-payment.paymentMethod"], |
| 29 | + ] |
| 30 | + }, |
| 31 | + { |
| 32 | + "collection": "collection_name", |
| 33 | + "cap": null, |
| 34 | + "index": [ |
| 35 | + ["-userId"] |
| 36 | + ["username"], |
| 37 | + ["-createdAt", "-user.email"], |
| 38 | + ] |
| 39 | + } |
| 40 | + .... |
| 41 | + .... |
| 42 | + .... |
| 43 | +] |
| 44 | +``` |
| 45 | + |
| 46 | +- `Collection` is the collection name |
| 47 | +- `cap` collection cap size in bytes (not yet supported) |
| 48 | +- `index` array of indexes `-` sign before a column refers to the descending order and no sign before column name refers to the ascending order |
| 49 | + |
13 | 50 | ## Examples
|
14 | 51 |
|
15 | 52 | > See list of index changes before applying
|
16 | 53 | ```shell
|
17 |
| -$ index --config "xyz.json" --uri "mongodb://127.0.0.1:27017/database_name" |
| 54 | +$ indexer --config "xyz.json" --uri "mongodb://127.0.0.1:27017/database_name" |
18 | 55 |
|
19 | 56 | ```
|
20 | 57 |
|
21 | 58 | > Apply the index changes
|
22 | 59 | ```shell
|
23 |
| -$ index --config "xyz.json" --uri "mongodb://127.0.0.1:27017/database_name" --apply |
| 60 | +$ indexer --config "xyz.json" --uri "mongodb://127.0.0.1:27017/database_name" --apply |
24 | 61 | ```
|
25 | 62 |
|
26 | 63 | ## Todo
|
|
0 commit comments