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


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

語法如下所示 −

db.getCollectionNames();

可以使用另一個命令,即 collections。語法如下所示 −

show collections;

要在 Mongo 中列出所有集合,請使用上面的兩個函式。查詢如下所示 −

> 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"
]

以下是用於顯示 Mongo 中所有集合的第二個查詢。查詢如下所示 −

> 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

更新時間: 2019-07-30

7 千 + 瀏覽次數

開啟你的 職業生涯

完成課程認證

開始學習
廣告
© . All rights reserved.