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.
In MongoDB, db. collection. drop() method is used to drop a collection from a database. It completely removes a collection from the database and does not leave any indexes associated with the dropped collections.
Yes, to all.
The remove() Method MongoDB's remove() method is used to remove a document from the collection. remove() method accepts two parameters. One is deletion criteria and second is justOne flag. deletion criteria − (Optional) deletion criteria according to documents will be removed.
The drop command removes the specified collection or view from the federated database instance storage configuration. Use the wildcard "*" to remove all collections generated by the wildcard collection function (that is, collectionName() ), including the wildcard collection rule itself.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With