Navigation

drop

Beta

The Atlas Data Lake is available as a Beta feature. The product and the corresponding documentation may change at any time during the Beta stage. For support, see Atlas Support.

The drop command removes the specified collection from the Atlas Data Lake storage configuration. Use the wildcard "*" to remove all collections generated by the wildcard collection function (that is, collectionName()), including the wildcard collection rule itself. You cannot individually remove collections generated by the wildcard collection function.

Syntax

db.runCommand({ "drop" : "<collection-name|*>" })

Parameters

Parameter Type Description Required?
<collection-name> string

The name of the collection to remove or the wildcard "*" . You can specify the wildcard "*" to drop:

  • All collections generated by the wildcard collection function (collectionName())
  • The wildcard collection rule
yes

Output

The command prints the following output if it succeeds. You can verify the results by running the show collections command. If the command fails, see Troubleshoot Errors for recommended solutions.

{ "ok" : 1, "ns" : "<database>.<collection>", "nIndexesWas" : 0 }

where:

  • <ns> reflects the collection namespace, which includes the database name, the dot (.) separator, and the collection name. For example: <database>.<collection>
  • nIndexesWas reflects the number of indexes, the value of which is always 0 on Atlas Data Lake.

Examples

The following examples use the drop command to remove sample collections that were mapped to the sample dataset, AirBnB and weather, in the AWS S3 store. See Getting Started with Atlas Data Lake tutorial for information on preparing your S3 bucket and uploading the sample dataset.

Basic Example

The following example uses the drop command to remove a sample collection named airbnb in a database named sample in the storage configuration.

use sample
db.runCommand({ "drop" : "airbnb"})

The previous command prints the following output:

{ "ok" : 1, "ns" : "sample.airbnb", "nIndexesWas" : 0 }

Wildcard Example

The following example uses the drop command to remove the wildcard collection function (collectionName()) and all collections created by the wildcard collection function in a database named sample in the storage configuration.

use sample
db.runCommand ({ "drop" : "*" })

The previous command prints the following output:

{ "ok" : 1, "ns" : "sample.*", "nIndexesWas" : 0 }

Troubleshoot Errors

If the command fails, it returns one of the following errors.

Reason: Namespace (database or collection) does not exist.

{
   ok: 0,
   errmsg: "ns not found",
   code: 26,
   codeName: "NamespaceNotFound"
}

Solution: Ensure that the namespace specified in the command is valid and exists in the storage configuration. If necessary, use the getStorageConfig command to retrieve the list of valid databases and collections in the storage configuration.

Reason: Attempting to remove a collection created by the wildcard collection function (collectionName()).

{
   ok: 0,
   errmsg: "cannot drop a collection created from a wildcard",
   code: 26,
   codeName: "NamespaceNotFound"
}

Solution: Ensure that the collection you are dropping is not an individual collection dynamically generated by the wildcard collection function (collectionName()). Data Lake does not support dropping individual collections generated by the wildcard collection function.

←   create renameCollection  →