TAGS :Viewed: 19 - Published at: a few seconds ago

[ Dropping all collections in Mongoengine ]

I have searched the api, but can't find anything relating to the dropping of a database without iterating through the collections manually.

Is there a simpler way of calling db.dropDatabase() through mongoengine? Its not a big deal to iterate through just wanted a simpler way.

Answer 1


How about doing it this way?

from mongoengine import connect

db = connect('test')
db.drop_database('test')

Alternatively, you can get connection object from _get_db() method:

from mongoengine import connect
from mongoengine.connection import _get_db

connect('test')

db = _get_db()
db.connection.drop_database('test')