如何在 MongoDB shell 中列出所有集合?

mongodbdatabasebig data analytics

要在 MongoDB shell 中列出所有集合,可以使用 `getCollectionNames()` 函数。

语法如下:


db.getCollectionNames();

您还可以使用另一个命令 `collections`。语法如下:


show collections;

要列出 MongoDB 中的所有集合,请使用以上两个函数。查询语句如下:

> db.getCollectionNames();

以下是输出 −

[
   "ConvertStringToDateDemo",
   "IdUpdateDemo",
   "ProductsInformation",
   "addFieldDemo",
   "addNewFieldToEveryDocument",
   "arrayInnerElementsDemo",
   "arrayLengthGreaterThanOne",
   "arrayOfArraysDemo",
   "caseInsensitiveDemo",
   "changeDataType",
   "changeType",
   "charactersAllowedDemo",
   "charactersDemo",
   "checkFieldContainsStringDemo",
   "checkSequenceDemo",
   "combinationOfArrayDemo",
   "conditionalSumDemo",
   "convertStringToNumberDemo",
   "copyThisCollectionToSampleDatabaseDemo",
   "countDemo",
   "createSequenceDemo",
   "distinctCountValuesDemo",
   "distinctRecordDemo",
   "distinctWithMultipleKeysDemo",
   "employeeInformation",
   "filterArray",
   "findAllDuplicateKeyDocumentDemo",
   "findByMultipleArrayDemo",
   "findDuplicateByKeyDemo",
   "findDuplicateRecordsDemo",
   "findSpecificValue",
   "findValueInArrayWithMultipleCriteriaDemo",
   "getLastNRecordsDemo",
   "getParticularElementFromArrayDemo",
   "getPartuclarElement",
   "getSizeOfArray",
   "groupByDateDemo",
   "incrementValueInNestedArrayDemo",
   "insertIfNotExistsDemo",
   "nestedArrayDemo",
   "notLikeOpeartorDemo",
   "regExpOnIntegerDemo",
   "removeArrayDemo",
   "removeArrayElement",
   "removeArrayElements",
   "removeDuplicateDocumentDemo",
   "removeElementFromDoublyNestedArrayDemo",
   "removeFieldCompletlyDemo",
   "removeObject",
   "renameFieldDemo",
   "reverseRegexDemo",
   "searchArrayDemo",
   "selectSingleFieldDemo",
   "singleFieldDemo",
   "sortDemo",
   "sortInnerArrayDemo",
   "sourceCollection",
   "stringFieldLengthDemo",
   "test.js",
   "uniqueIndexOnArrayDemo",
   "unwindOperatorDemo",
   "updateExactField",
   "updateIdDemo",
   "updateObjects"
]

以下是显示 MongoDB 中所有集合的第二个查询。查询语句如下:−

> show collections;

以下是输出 −

ConvertStringToDateDemo
IdUpdateDemo
ProductsInformation
addFieldDemo
addNewFieldToEveryDocument
arrayInnerElementsDemo
arrayLengthGreaterThanOne
arrayOfArraysDemo
caseInsensitiveDemo
changeDataType
changeType
charactersAllowedDemo
charactersDemo
checkFieldContainsStringDemo
checkSequenceDemo
combinationOfArrayDemo
conditionalSumDemo
convertStringToNumberDemo
copyThisCollectionToSampleDatabaseDemo
countDemo
createSequenceDemo
distinctCountValuesDemo
distinctRecordDemo
distinctWithMultipleKeysDemo
employeeInformation
filterArray
findAllDuplicateKeyDocumentDemo
findByMultipleArrayDemo
findDuplicateByKeyDemo
findDuplicateRecordsDemo
findSpecificValue
findValueInArrayWithMultipleCriteriaDemo
getLastNRecordsDemo
getParticularElementFromArrayDemo
getPartuclarElement
getSizeOfArray
groupByDateDemo
incrementValueInNestedArrayDemo
insertIfNotExistsDemo
nestedArrayDemo
notLikeOpeartorDemo
regExpOnIntegerDemo
removeArrayDemo
removeArrayElement
removeArrayElements
removeDuplicateDocumentDemo
removeElementFromDoublyNestedArrayDemo
removeFieldCompletlyDemo
removeObject
renameFieldDemo
reverseRegexDemo
searchArrayDemo
selectSingleFieldDemo
singleFieldDemo
sortDemo
sortInnerArrayDemo
sourceCollection
stringFieldLengthDemo
test.js
uniqueIndexOnArrayDemo
unwindOperatorDemo
updateExactField
updateIdDemo
updateObjects

相关文章