MongoDB: The Definitive Guide

Author: Kristina Chodorow, Michael Dirolf
This Year Stack Overflow 1
This Month Stack Overflow 1


by anonymous   2019-01-13

The main difference is that db.remove({}) removes all documents but your collection still have metadata like indexes. The dropDatabase remove literally the entire collection including metadata.

If you are recreating collection indexes or you don't have it please use dropDatabase it's much faster.

Check this link to understand db.collection.drop() vs db.dropDatabase()

If you are into learning MongoDb I recommend reading this book. It also explains your use case.

by anonymous   2017-08-20

A benefit of simply dropping a collection is that it is much faster than removing all of a collection's documents. If your collection will be "re-created immediately" anyway (assuming that includes index re-creation), then this is probably the most-attractive option.

The authors of the book MongoDB: The Definitive Guide (Kristina Chodorow and Michael Dirolf) ran an experiment where they provided a Python script which timed a drop vs. a remove of 1000000 records. The results came in at 0.01 seconds for the drop and 46.08 seconds for the remove. Now while the exact times may differ based-on hardware and other factors, it nonetheless illustrates the point that the drop is significantly faster.

reference: Chodorow K., Dirolf M. (2010). “MongoDB: The Definitive Guide.” O'Reilly Media, Inc. Sebastapol, CA., pp.25