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

要列出Mongo shell中的所有集合,可以使用函数getCollectionNames()

语法如下-

db.getCollectionNames();

您可以使用另一个命令即集合。语法如下-

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

以上是 如何在Mongo Shell中列出所有集合? 的全部内容, 来源链接: utcz.com/z/321761.html

回到顶部