如何在 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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP