What is the method to clear data from a table in MongoDB?
To delete all data from a table (also known as a collection) in MongoDB, you can use one of the following methods:
- Use the remove() method to delete all documents in the collection.
db.collectionName.remove({})
- Use the drop() method to delete the entire collection and create a new empty collection.
db.collectionName.drop()
Before performing the above operation, make sure you have backed up the data that needs to be retained, as these operations will permanently delete all documents in the collection.