What is the command for deleting data in MongoDB?
The command to delete data in MongoDB is db.collection.remove(query, options). Here, db is the database object, collection is the name of the collection where data will be deleted, query is the condition for deletion, and options are optional parameters for the deletion operation.
If no query is specified, all documents in the collection will be deleted.
Here are some common examples of commands for deleting data:
- Remove all documents from the collection.
 
db.collection.remove({})
- Delete documents that meet the criteria.
 
db.collection.remove({ field: value })
- Delete documents that meet the criteria, and remove only the first matching document.
 
db.collection.remove({ field: value }, { justOne: true })
- Delete documents that meet the criteria and return the deleted documents.
 
db.collection.findAndRemove({ field: value })
Please note that deleting data is irreversible, so please use caution. Before deleting data, it is recommended to backup the data or use the find command to confirm the data to be deleted.