I’m trying to create search indexes using golang driver. I’m attempting the task with the below code:
definition := bson.D{{"mappings", bson.D{{"dynamic", false}}}}
opts := options.SearchIndexes().SetName("search_index")
index, err := client.Database(config.MongoDbName).Collection("marketplace_item").SearchIndexes().CreateOne(ctx, mongo.SearchIndexModel{
Definition: definition,
Options: opts,
})
if err != nil {
return fmt.Errorf("failed to create search index: %w", err)
}
But I’m getting the following error:
error: failed to create search index: (CommandNotFound) command not found {"error": {"kind":"*fmt.wrapError","stack":"","message":"Failed to run the migration, error: failed to create search index: (CommandNotFound) command not found"}}
Not sure what’s going wrong, because the above code is similar to the test suite in the golang driver repo.