Cannot create Atlas Search Index using Go Driver

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.

Hi @Gokul_Ks , what tier of Atlas are you running this on? Note the below limitation from the docs which we are working on addressing soon:

You can’t use the mongosh command or driver helper methods to create Atlas Search indexes on M0 , M2 , or M5 Atlas clusters. To create and manage Atlas Search indexes using mongosh or the driver, upgrade to a dedicated cluster tier.

1 Like

Thanks for taking you time to reply. I found this limitation by digging around a bit, which is exactly the issue since I was attempting to run this command on a M0 cluster.