A2oz

How Do I Delete All Documents in MongoDB Compass?

Published in MongoDB Compass 2 mins read

You can delete all documents in a MongoDB collection using the "Delete" feature in MongoDB Compass. Here's how:

  1. Open MongoDB Compass: Launch the MongoDB Compass application.
  2. Select the Database and Collection: Navigate to the database and collection you want to clear.
  3. Click the "Delete" Button: Locate the "Delete" button on the collection's toolbar, usually represented by a trash can icon.
  4. Confirm the Deletion: A confirmation dialog will appear. Review the message and confirm the deletion by clicking the "Delete" button.

Important Considerations:

  • Data Loss: Deleting all documents is irreversible. Make sure you have a backup or are comfortable losing the data before proceeding.
  • Alternative Methods: You can also use the MongoDB shell or other tools to delete documents.

Example:

Let's say you have a collection named "users" in a database called "mydatabase." To delete all documents in the "users" collection, follow these steps:

  1. Open MongoDB Compass.
  2. Navigate to the "mydatabase" database and select the "users" collection.
  3. Click the "Delete" button on the collection's toolbar.
  4. Confirm the deletion in the dialog box.

Remember: This action will permanently delete all documents in the "users" collection.

Related Articles