如何从所有MongoDB数据库中获取所有集合?

要从所有数据库中获取所有集合,让我们首先使用以下查询来获取所有数据库

> switchDatabaseAdmin = db.getSiblingDB("admin");

admin

> allDatabaseName = switchDatabaseAdmin.runCommand({ "listDatabases": 1 }).databases;

这将产生以下输出

[

   {

      "name" : "admin",

      "sizeOnDisk" : 495616,

      "empty" : false

   },

   {

      "name" : "config",

      "sizeOnDisk" : 98304,

      "empty" : false

   },

   {

      "name" : "local",

      "sizeOnDisk" : 73728,

      "empty" : false

   },

   {

      "name" : "sample",

      "sizeOnDisk" : 1335296,

      "empty" : false

   },

   {

      "name" : "sampleDemo",

      "sizeOnDisk" : 278528,

      "empty" : false

   },

   {

      "name" : "studentSearch",

      "sizeOnDisk" : 262144,

      "empty" : false

   },

   {

      "name" : "test",

      "sizeOnDisk" : 8724480,

      "empty" : false

   }

]

以下是从数据库获取所有集合名称的查询

> allDatabaseName.forEach(function(databaseName)

... {

...    db = db.getSiblingDB(databaseName.name);

...    collectionName = db.getCollectionNames();

...    collectionName.forEach(function(collectionName)

...    {

...       print(collectionName);

...    });

... });

这将产生以下输出

clearingItemsInNestedArrayDemo

customIdDemo

deleteRecordDemo

documentExistsOrNotDemo

findAllExceptFromOneOrtwoDemo

mongoExportDemo

startup_log

arraySizeErrorDemo

basicInformationDemo

copyThisCollectionToSampleDatabaseDemo

deleteAllRecordsDemo

deleteDocuments

deleteDocumentsDemo

deleteSomeInformation

documentWithAParticularFieldValueDemo

employee

findListOfIdsDemo

findSubstring

getAllRecordsFromSourceCollectionDemo

getElementWithMaxIdDemo

internalArraySizeDemo

largestDocumentDemo

makingStudentInformationClone

oppositeAddToSetDemo

prettyDemo

returnOnlyUniqueValuesDemo

selectWhereInDemo

sourceCollection

studentInformation

sumOfValueDemo

truncateDemo

updateInformation

userInformation

copyThisCollectionToSampleDatabaseDemo

deleteDocuments

deleteDocumentsDemo

deleteInformation

employee

internalArraySizeDemo

prettyDemo

sourceCollection

updateInformation

userInformation

col1

col2

indexingForArrayElementDemo

removeObjectFromArrayDemo

specifyAKeyDemo

useVariableDemo

ConvertStringToDateDemo

Employee_Information

IdUpdateDemo

IndexingDemo

NotAndDemo

ProductsInformation

addCurrentDateTimeDemo

addFieldDemo

addNewFieldToEveryDocument

aggregateSumDemo

aggregationFrameworkWithOrMatchDemo

aggregationSortDemo

andOrDemo

arrayInnerElementsDemo

arrayLengthGreaterThanOne

arrayOfArraysDemo

avoidDuplicateEntriesDemo

caseInsensitiveDemo

caseInsesitiveDemo

castingDemo

changeDataType

changeType

charactersAllowedDemo

charactersDemo

checkFieldContainsStringDemo

checkFieldExistsOrNotDemo

checkSequenceDemo

collectionOnDifferentDocumentDemo

combinationOfArrayDemo

comparingTwoFieldsDemo

concatStringAndIntDemo

conditionalSumDemo

convertStringToNumberDemo

copyThisCollectionToSampleDatabaseDemo

countDemo

countPerformanceDemo

createSequenceDemo

creatingUniqueIndexDemo

dateDemo

deleteAllElementsInArrayDemo

deleteRecordDemo

demo.insertCollection

distinctAggregation

distinctCountValuesDemo

distinctRecordDemo

distinctWithMultipleKeysDemo

doubleNestedArrayDemo

embeddedCollectionDemo

employeeInformation

equivalentForSelectColumn1Column2Demo

fieldIsNullOrNotSetDemo

filterArray

findAllDuplicateKeyDocumentDemo

findAllNonDistinctDemo

findByMultipleArrayDemo

findDocumentDoNotHaveCertainFields

findDocumentNonExistenceFieldDemo

findDocumentWithObjectIdDemo

findDuplicateByKeyDemo

findDuplicateRecordsDemo

findMinValueDemo

findSpecificValue

findValueInArrayWithMultipleCriteriaDemo

firstDocumentDemo

firstItemInArrayToNewFieldDemo

getDistinctListOfSubDocumentFieldDemo

getFirstItemDemo

getIndexSizeDemo

getLastNRecordsDemo

getLastXRecordsDemo

getNThElementDemo

getParticularElementFromArrayDemo

getPartuclarElement

getSizeDemo

getSizeOfArray

gettingHighestValueDemo

groupByDateDemo

hideidDemo

identifyLastDocuementDemo

incrementValueDemo

incrementValueInNestedArrayDemo

indexDemo

indexOptimizationDemo

indexTimeDemo

index_Demo

indexingDemo

insertDemo

insertFieldWithCurrentDateDemo

insertIfNotExistsDemo

insertIntegerDemo

insertOneRecordDemo

listAllValuesOfCeratinFieldsDemo

matchBetweenFieldsDemo

mongoExportDemo

multipleOrDemo

my-collection

nestedArrayDemo

nestedIndexDemo

nestedObjectDemo

new_Collection

notLikeOpeartorDemo

numberofKeysInADocumentDemo

objectInAnArrayDemo

objectidToStringDemo

orConditionDemo

orDemo

orderDocsDemo

paginationDemo

performRegex

priceStoredAsStringDemo

priceStoredDemo

queryArrayElementsDemo

queryByKeyDemo

queryBySubFieldDemo

queryForBooleanFieldsDemo

queryInSameDocumentsDemo

queryToEmbeddedDocument

queryingMongoDbCaseInsensitiveDemo

regExpOnIntegerDemo

regexSearchDemo

removeArrayDemo

removeArrayElement

removeArrayElementByItsIndexDemo

removeArrayElements

removeDocumentOnBasisOfId

removeDuplicateDocumentDemo

removeDuplicateDocuments

removeElementFromDoublyNestedArrayDemo

removeFieldCompletlyDemo

removeMultipleDocumentsDemo

removeObject

removingidElementDemo

renameFieldDemo

retrieveValueFromAKeyDemo

retunFieldInFindDemo

returnQueryFromDate

reverseRegexDemo

s

searchArrayDemo

searchDocumentDemo

searchDocumentWithSpecialCharactersDemo

searchMultipleFieldsDemo

secondDocumentDemo

selectInWhereIdDemo

selectMongoDBDocumentsWithSomeCondition

selectRecordsHavingKeyDemo

selectSingleFieldDemo

singleFieldDemo

sortDemo

sortInnerArrayDemo

sortingDemo

sourceCollection

sqlLikeDemo

stringFieldLengthDemo

stringToObjectIdDemo

test.js

translateDefinitionDemo

unconditionalUpdatesDemo

uniqueIndexOnArrayDemo

unprettyJsonDemo

unwindOperatorDemo

updateDemo

updateExactField

updateIdDemo

updateManyDocumentsDemo

updateNestedValueDemo

updateObjects

updatingEmbeddedDocumentPropertyDemo

userStatus

以上是 如何从所有MongoDB数据库中获取所有集合? 的全部内容, 来源链接: utcz.com/z/343553.html

回到顶部