0

Which option is best for removing all elements of a large collection in a heavily used prod database? A bulk.find({}).remove() vs removeAll() vs dropCollection() or maybe another strategy?

By the mongo documentation, dropCollection locks the entire DB where the collection sits while it proceeds, which is not acceptable for an heavily used prod DB.

Time wise, a removeAll() take slightly more time vs a bulk.find({}).remove() (tested each on exact same collection of roughly ~700k).

Jeep87c
  • 1,050
  • 16
  • 36
  • Moreover, please refrain from posting any type of *"Which is Best?"* question. Such questions are basically opinionated and very rarely is there a case for someone to provide some actual expert input. For this reason they are basically "off-topic" and promptly removed from this site. As for the general format of what you posted here, then your own "bench-marking" should be enough for you to make up your mind which you want to use. – Neil Lunn Nov 14 '18 at 22:16
  • Also, not sure what you are using but the official API spec the method would be `deleteMany()` Methods named `remove` have actually been deprecated, and I don't know of any official driver using `removeAll()`. And FYI the `deleteMany()` and in fact ALL such operations for the MongoDB API actually use the "Bulk" API directly. So effectively the calls are exactly the same thing. – Neil Lunn Nov 14 '18 at 22:19

0 Answers0