I’m doing development on MongoDB. For totally non-evil purposes, I sometimes want to blow away everything in a database—that is, to delete every single collection, and whatever else might be lying around, and start from scratch. Is there a single line of code that will let me do this? Bonus points for giving both a MongoDB console method and a MongoDB Ruby driver method.
mongo DATABASE_NAME --eval "db.dropDatabase()"
root@Avalon:/home/# mongo avalon --eval "db.dropDatabase()"
MongoDB shell version v4.2.22
connecting to: mongodb://127.0.0.1:27017/avalon?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("bea7a56f-a31c-49ca-85ab-6f95fe93a689") }
MongoDB server version: 4.2.22
{ "dropped" : "avalon", "ok" : 1 }
5/5 - (1 vote)