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