Documentation ¶
Overview ¶
Package index provides functions to create MongoDB indexes from YAML configuration files.
Index ¶
- type Config
- type Result
- func Create(ctx context.Context, db *mongo.Database, filepath string, ...) (Result, error)
- func CreateFromBytes(ctx context.Context, db *mongo.Database, yaml []byte, ...) (Result, error)
- func CreateFromConfig(ctx context.Context, db *mongo.Database, cfg Config, ...) (Result, error)
- func CreateFromReader(ctx context.Context, db *mongo.Database, r io.Reader, ...) (Result, error)
- func CreateFromString(ctx context.Context, db *mongo.Database, yaml string, ...) (Result, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config map[string][]mongo.IndexModel
Config is the index configuration for the collections.
type Result ¶
type Result struct { // How many indexes were created. Count int // Names of the created indexes categorized by collection name. Names map[string][]string }
Result contains information about the created indexes.
func Create ¶
func Create(ctx context.Context, db *mongo.Database, filepath string, opts ...*options.CreateIndexesOptions) (Result, error)
Create creates the indexes for db from the provided YAML configuration file.
Example ¶
package main import ( "context" "fmt" "log" "github.com/bounoable/mongoutil/index" "go.mongodb.org/mongo-driver/mongo" ) func main() { ctx := context.Background() client, _ := mongo.Connect(ctx) db := client.Database("dbname") result, err := index.Create(ctx, db, "/path/to/config.yml") if err != nil { log.Fatal(err) } fmt.Printf("created %d indexes: \n%v\n", result.Count, result.Names) }
Output:
func CreateFromBytes ¶
func CreateFromBytes(ctx context.Context, db *mongo.Database, yaml []byte, opts ...*options.CreateIndexesOptions) (Result, error)
CreateFromBytes creates the indexes for db from the provided configuration in YAML format.
func CreateFromConfig ¶
func CreateFromConfig(ctx context.Context, db *mongo.Database, cfg Config, opts ...*options.CreateIndexesOptions) (Result, error)
CreateFromConfig creates the indexes for db from the provided configuration.
Click to show internal directories.
Click to hide internal directories.