如何在 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 千 + 浏览次数

开启你的 职业生涯

完成课程认证

开始学习
广告