कमांड लाइन से MongoDB डेटाबेस ड्रॉप (हटाने) के लिए mongo कमांड के साथ --eval विकल्प का उपयोग करें।
सिंटैक्स
mongo yourDatabaseName --eval "db.dropDatabase()"
उदाहरण से समझें
पहले सभी डेटाबेस लिस्ट करें:
> show dbs;
आउटपुट:
StudentTracker 0.000GB admin 0.000GB config 0.000GB local 0.000GB sample 0.000GB test 0.003GB
अब कमांड लाइन से StudentTracker डेटाबेस ड्रॉप करें:
C:\Program Files\MongoDB\Server\4.0\bin>mongo StudentTracker --eval "db.dropDatabase()"
आउटपुट:
MongoDB shell version v4.0.5
connecting to: mongodb://127.0.0.1:27017/StudentTracker?gssapiServiceName=mongodb
Implicit session: session { "id": UUID("afc34e93-b4c0-46f0-85bd-b80ed17b8c11") }
MongoDB server version: 4.0.5
{ "dropped": "StudentTracker", "ok": 1 }
फिर से डेटाबेस लिस्ट करके वेरिफाई करें:
> show dbs
आउटपुट:
admin 0.000GB config 0.000GB local 0.000GB sample 0.000GB test 0.003GB
StudentTracker डेटाबेस सफलतापूर्वक ड्रॉप हो गया। "ok": 1 सफलता दर्शाता है।
सावधानी: यह ऑपरेशन अपरिवर्तनीय है - सभी डेटा स्थायी रूप से हट जाएगा।