Drop a collection
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
-
Python
-
TypeScript
-
Java
-
curl
Deletes the specified collection from the database and erases all data stored in the collection.
The method returns None
upon successful completion.
Deletes the specified collection from the database and erases all data stored in the collection.
Returns a promise that resolves once the operation completes.
Deletes the specified collection from the database and erases all data stored in the collection.
Does not return anything.
Deletes the specified collection from the database and erases all data stored in the collection.
If the command succeeds, the response indicates the success.
Example response:
{
"status": {
"ok": 1
}
}
Parameters
-
Python
-
TypeScript
-
Java
-
curl
Use the drop_collection
method, which belongs to the astrapy.Database
class.
Method signature
drop_collection(
name: str,
*,
keyspace: str,
collection_admin_timeout_ms: int,
request_timeout_ms: int,
timeout_ms: int,
) -> None:
Name | Type | Summary |
---|---|---|
|
|
The name of the collection to drop. |
|
|
The keyspace containing the collection. If no keyspace is specified, the general setting for this database is used. |
|
|
A timeout, in milliseconds, for the underlying HTTP request.
If not provided, the |
Use the dropCollection
method, which belongs to the Db
class.
Method signature
async dropCollection(
name: string,
options?: {
keyspace?: string,
timeout?: number | TimeoutDescriptor,
}
): void
Name | Type | Summary |
---|---|---|
|
|
The name of the collection to delete. |
|
Allows you to override the keyspace and set timeouts. |
Options (DropCollectionOptions
):
Name | Type | Summary |
---|---|---|
|
The keyspace containing the collection. If not specified, the database’s working keyspace is used. |
|
|
|
Optional. The timeout(s) to apply to this method.
You can specify Details about the
|
Use the dropCollection
method, which belongs to the com.datastax.astra.client.Database
class.
Method signature
void dropCollection(String collectionName)
void dropCollection(
String collectionName,
DropCollectionOptions options
)
Name | Type | Summary |
---|---|---|
|
|
The name of the collection to delete. |
Use the deleteCollection
command.
Command signature
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/ASTRA_DB_KEYSPACE" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"deleteCollection": {
"name": "COLLECTION_NAME"
}
}'
Name | Type | Summary |
---|---|---|
|
|
The command to delete a specified collection and all of its data. |
|
|
The name of the collection to delete. |
Examples
The following examples demonstrate how to drop a collection.
-
Python
-
TypeScript
-
Java
-
curl
result = db.drop_collection("COLLECTION")
Example:
from astrapy import DataAPIClient
client = DataAPIClient()
database = client.get_database("API_ENDPOINT", token="TOKEN")
database.list_collection_names()
# prints: ['a_collection', 'my_v_col', 'another_col']
database.drop_collection("my_v_col")
database.list_collection_names()
# prints: ['a_collection', 'another_col']
The database’s drop_collection
method is equivalent to the collection’s own method collection.drop()
.
After invoking the latter, however, keep in mind that calling any subsequent operation
on the collection will result in an error.
await db.dropCollection('COLLECTION');
Example:
import { DataAPIClient } from '@datastax/astra-db-ts';
// Get a new Db instance
const db = new DataAPIClient('TOKEN').db('API_ENDPOINT');
(async function () {
// Uses db's default keyspace
await db.dropCollection('COLLECTION_NAME');
// Overrides db's default keyspace
await db.dropCollection('COLLECTION_NAME', {
keyspace: 'KEYSPACE_NAME'
});
})();
Example:
package com.datastax.astra.client.database;
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.databases.Database;
import com.datastax.astra.client.collections.commands.options.DropCollectionOptions;
public class DropCollection {
public static void main(String[] args) {
Database db = new DataAPIClient("TOKEN")
.getDatabase("API_ENDPOINT");
// Delete an existing collection
DropCollectionOptions options = new DropCollectionOptions();
db.dropCollection("collection_vector2", options);
}
}
To delete a collection and all data that it contains, send a POST request with the deleteCollection
command:
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/ASTRA_DB_KEYSPACE" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"deleteCollection": {
"name": "COLLECTION_NAME"
}
}' | jq
Client reference
-
Python
-
TypeScript
-
Java
-
curl
For more information, see the client reference.
For more information, see the client reference.
For more information, see the client reference.
Client reference documentation is not applicable for HTTP.