Index Management
Index Management
Section titled “Index Management”Pie provides automated index creation and management functionality.
Basic Usage
Section titled “Basic Usage”// Create index managerindexes := pie.MustIndexes(engine)
// Create indexes for structerr := indexes.CreateIndexes(ctx, User{})
// Manual index creationerr := indexes.CreateIndex(ctx, "users", bson.D{ {"email", 1},}, &options.IndexOptions{ Unique: pie.Bool(true),})Struct Tags
Section titled “Struct Tags”type User struct { ID bson.ObjectID `bson:"_id,omitempty"` Name string `bson:"name" pie:"index"` Email string `bson:"email" pie:"unique"` Age int `bson:"age" pie:"index,sparse"` CreatedAt time.Time `bson:"created_at" pie:"index"`}Next Steps
Section titled “Next Steps”- Change Streams - Learn about change streams
- Query Scopes - Learn about query scopes
- Performance - Learn performance optimization