How to check if a collection exists and delete it?

Just drop the collection every time, additional access to the collection will create it.

drop(options, callback){Promise}

lib/collection.js, line 1140

Drop the collection from the database, removing it permanently. New accesses will create a new collection.

http://mongodb.github.io/node-mongodb-native/3.5/api/Collection.html#drop

1 Like