MongoDB में किसी विशेष डेटाबेस के सभी संग्रहों के नाम सूचीबद्ध करने के लिए, पहले use <databaseName> के साथ डेटाबेस पर स्विच करें, फिर db.getCollectionNames() चलाएं।
सिंटैक्स
use yourDatabaseName; db.getCollectionNames();
उदाहरण: 'web' डेटाबेस के लिए
> use web; switched to db web > db.getCollectionNames();
नमूना आउटपुट
[
"2015-myCollection",
"2015-yourCollection",
"2019-employeeCollection",
"addColumnDemo",
"applyConditionDemo",
"calculateAverage",
"calculateSumOfDocument",
"changeSimpleFieldDemo",
"check",
"checkFieldDemo",
"collationExample",
"compoundIndexDemo",
"countandsumdemo",
"creatingAliasDemo",
"decreasetimeusingindex",
"demo1",
"demo10",
"demo11",
"demo12",
"demo13",
"demo14",
"demo15",
"demo16",
"demo17",
"demo18",
"demo19",
"demo2",
"demo20",
"demo21",
"demo22",
"demo23",
"demo24",
"demo25",
"demo26",
"demo27",
"demo28.example",
"demo29",
"demo3",
"demo30",
"demo31",
"demo32",
"demo33",
"demo34",
"demo35",
"demo36",
"demo37",
"demo38",
"demo39",
"demo4",
"demo5",
"demo6",
"demo7",
"demo8",
"demo9",
"destinationCollection",
"emp_info",
"emptyCollection",
"extractParticularElementDemo",
"getSpecificData",
"getTheMaxValueDemo",
"indexCreationDemo",
"missingDocumentDemo",
"promoteSubfieldsDemo",
"pullWithPositionalOperatorDemo",
"removeNullDemo",
"replacevaluedemo",
"searchDocumentsDemo",
"searchSubFieldDemo",
"sourceCollection",
"splitString",
"testInArray",
"twoSpecificIdsDemo",
"updatingDemo",
"version"
]
वैकल्पिक मेथड्स
show collections— शेल शॉर्टकट (वर्तमान डेटाबेस के लिए)।db.getCollectionInfos()— प्रत्येक संग्रह के लिए विस्तृत मेटाडेटा (विकल्प, इंडेक्स जानकारी) लौटाता है।db.runCommand({listCollections: 1})— निम्न-स्तरीय कमांड।
नोट
सिस्टम संग्रह (जैसे system.indexes) डिफ़ॉल्ट रूप से छिपे होते हैं; उन्हें शामिल करने के लिए db.getCollectionNames({includeSystemCollections: true}) का उपयोग करें।