Drop a collection (Go)
Deletes a collection from a database and erases all data stored in the collection.
|
Ready to write code? See the examples for this method to get started. If you are new to the Data API, check out the quickstart. |
Result
Deletes the specified collection from the database and erases all data stored in the collection.
A successful operation does not return anything.
Parameters
Use the DropCollection method, which belongs to the Db type.
Method signature
func (d *Db) DropCollection(
ctx context.Context,
name string,
opts ...options.DropCollectionOption
) error
| Name | Type | Summary |
|---|---|---|
|
|
The context for the operation. |
|
|
The name of the collection to drop. |
|
Optional.
A builder to generate options for this operation.
See Methods of the |
| Method | Summary |
|---|---|
|
Optional. The keyspace containing the collection. Default: The working keyspace for the database.
This is |
|
Optional. General API options for this operation, including the timeout. |
Examples
The following examples demonstrate how to drop a collection.
package main
import (
"context"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
)
func main() {
ctx := context.Background()
// Get a database
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
// Drop a collection
err := database.DropCollection(ctx, "COLLECTION_NAME")
if err != nil {
log.Fatal(err)
}
}
Client reference
For more information, see the client reference.