splice-action-indexes
is for managing MongoDB indexes and Atlas Search indexes in your project. It provides a set of scripts to download, inspect, and write index configurations, along with the ability to post comments on GitHub pull requests regarding any changes to your indexes. It reads index specifications from .json
files stored in the actions/action-indexes/indexes/{DATABASE_NAME}/
directory in your project. Each subdirectory within .../indexes/{DATABASE_NAME}/
represents a collection in your MongoDB database, and the files within those subdirectories define indexes for those collections. File names are used as index names. Files meant for Atlas Search indexes include .search
in their filename (e.g., index_name.search.json
) and contain an object with the search index definition.
-
Automatic Index Creation: Automatically creates or updates indexes based on the
.json
files found in the.../indexes/{DATABASE_NAME}/
directory. - Support for Atlas Search Indexes: Distinguishes between standard indexes and Atlas Search indexes, allowing for the creation of both types from the specified files.
- Collection-Specific Indexing: Organizes index files by MongoDB collection names, allowing for clear and manageable index specifications.
-
File Structure:
- The
actions/action-indexes/indexes/{DATABASE_NAME}/
directory contains subdirectories named after your MongoDB collections. - Each subdirectory contains
.json
files, where each file defines an index for that collection. - Standard index files are named
<indexName>.json
and contain the field specification and index metadata as an array. - Atlas Search index files are named
<indexName>.search.json
and contain the search index definition as an object.
- The
-
Index File Format:
-
Standard Index Files: Contain an array with the field specification and index metadata.
[ { "fieldName": 1 }, { "v": 2, "name": "index_name" } ]
-
Atlas Search Index Files: Contain an object with the search index definition.
{ "name": "index_name", "mappings": { "dynamic": true, ... }, }
-
-
Usage:
You can import and use the scripts as follows:
-
Downloading Indexes
To download indexes, including Atlas Search configurations, use:
import { download } from '@mrmtech/splice-action-indexes'; await download({ scriptUrl: import.meta.url, indexFolder: '{DATABASE_NAME}' });
-
Inspecting Indexes
To inspect the MongoDB indexes (both standard and Atlas Search), use:
import { inspect } from '@mrmtech/splice-action-indexes'; await inspect();
-
Writing Indexes
To write or update indexes in your MongoDB, including Atlas Search indexes, use:
import { write } from '@mrmtech/splice-action-indexes'; await write();
-
Commenting on Pull Requests
To post a comment on a GitHub pull request regarding index changes, use:
import { comment } from '@mrmtech/splice-action-indexes'; await comment();
-
Package Scripts
The following scripts are defined in the package.json file, making it easy to run the various functions:
{ "scripts": { "splice-action-indexes:link": "pnpm link ../../../splice/actions/splice-action-indexes", "splice-action-indexes:unlink": "pnpm unlink ../../../splice/actions/splice-action-indexes", "comment": "node comment.js", "inspect": "node inspect.js --mongodb_uri=$MONGODB_URI --index_folder={DATABASE_NAME}", "write": "node write.js --mongodb_uri=$MONGODB_URI --index_folder={DATABASE_NAME}", "download": "infisical run --env=dev --path=/ -- node download.js", "inspect-local": "infisical run --env=dev --path=/ -- node inspect.js --index_folder={DATABASE_NAME}", "write-local": "infisical run --env=dev --path=/ -- node write.js --index_folder={DATABASE_NAME}" } }
-