to remove the collection from the database through db.collectionName.drop() method.
Syntax:-
db.collectionName.drop()
Note:- if the collection exists then show message true if the collection does not exist then show message false;
Suppose, You have two collections department and employees. Now, check the collections in MongoDB
show collections
Output:-
department
employees
employees
Example:-
db.employees.drop()
Output:-
true
Now get the collection
show collection
Output:-
department
Drop Collection – Interview Questions
Q 1: How do you delete a collection?
Ans: Use db.collectionName.drop().
Q 2: What does drop() return?
Ans: Returns true if successful.
Q 3: Does drop collection delete all documents?
Ans: Yes, it removes the entire collection and documents.
Q 4: Can you restore the dropped collection?
Ans: Only if backup exists.
Q 5: Is dropping the collection permanent?
Ans: Yes.