Help Center/
Document Database Service/
Developer Guide/
Database Usage Suggestions/
Basic Commands/
Delete
Updated on 2022-09-21 GMT+08:00
Delete
- The delete operation is classified into logical delete (condition-based remove) and quick delete (dropCollection, dropDatabase).
- After a large number of delete operations are performed, the actual data volume may not change, but the storage space usage increases. This is because operations such as write, update, delete, and index insert and delete are actually converted to write in the background. The underlying storage engines (WiredTiger and RocksDB) use appendOnly. Only when the internal data status of the storage engine meets certain conditions, the compaction operation is triggered to compress data and release storage space.
- If the entire database is not required, you can run dropDatabase to delete it instead of logically deleting it to quickly release disk space.
- The delete operation involves synchronization to the standby node. You can specify the writeConcern level for the delete operation. For details, see Write Concern.
Precaution
- Avoid mis-deletion. The delete command cannot be undone. Before the deletion, run db to check whether the current database is opened.
- If data is deleted by mistake, restore the data:
- Back up and restore data based on historical backup files.
- If a backup instance is available, you can restore the deleted data by referring to Migrating data using the export and import tools. If new data is written during the restoration, restoring data may affect data consistency.
- Data generated from the last backup time to the time when the instance is deleted by mistake cannot be restored.
- If the delete command is executed successfully, the deletion is successful. If the delete command fails, some data may have been deleted. Do not use the deleted database table. You are advised to continue to run the delete command until the deletion is successful.
Parent topic: Basic Commands
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.
The system is busy. Please try again later.