Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> MongoDB

แสดงรายชื่อคอลเลกชันในฐานข้อมูล MongoDB เฉพาะฐานข้อมูล

ใช้คำสั่ง use <database> สลับฐานข้อมูล แล้ว 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",
    "demo2",
    "demo3",
    "demo4",
    "demo5",
    "demo6",
    "demo7",
    "demo8",
    "demo9",
    "demo10",
    "demo11",
    "demo12",
    "demo13",
    "demo14",
    "demo15",
    "demo16",
    "demo17",
    "demo18",
    "demo19",
    "demo20",
    "demo21",
    "demo22",
    "demo23",
    "demo24",
    "demo25",
    "demo26",
    "demo27",
    "demo28.example",
    "demo29",
    "demo30",
    "demo31",
    "demo32",
    "demo33",
    "demo34",
    "demo35",
    "demo36",
    "demo37",
    "demo38",
    "demo39",
    "destinationCollection",
    "emp_info",
    "emptyCollection",
    "extractParticularElementDemo",
    "getSpecificData",
    "getTheMaxValueDemo",
    "indexCreationDemo",
    "missingDocumentDemo",
    "promoteSubfieldsDemo",
    "pullWithPositionalOperatorDemo",
    "removeNullDemo",
    "replacevaluedemo",
    "searchDocumentsDemo",
    "searchSubFieldDemo",
    "sourceCollection",
    "splitString",
    "testInArray",
    "twoSpecificIdsDemo",
    "updatingDemo",
    "version"
]

คำสั่งเก่า: show collections (ยังใช้ได้แต่ getCollectionNames() เป็นมาตรฐาน)