Để lấy tất cả các bộ sưu tập từ tất cả các cơ sở dữ liệu, trước tiên chúng ta hãy lấy tất cả các cơ sở dữ liệu bằng cách sử dụng truy vấn sau
> switchDatabaseAdmin =db.getSiblingDB ("admin"); admin> allDatabaseName =switchDatabaseAdmin.runCommand ({"listDatabases":1}). cơ sở dữ liệu;
Điều này sẽ tạo ra kết quả sau
[{"name":"admin", "sizeOnDisk":495616, "blank":false}, {"name":"config", "sizeOnDisk":98304, "blank":false}, {" name ":" local "," sizeOnDisk ":73728," blank ":false}, {" name ":" sample "," sizeOnDisk ":1335296," blank ":false}, {" name ":" sampleDemo " , "sizeOnDisk":278528, "blank":false}, {"name":"studentSearch", "sizeOnDisk":262144, "blank":false}, {"name":"test", "sizeOnDisk":8724480 , "trống":false}]
Sau đây là truy vấn để lấy tất cả các tên bộ sưu tập từ cơ sở dữ liệu
> allDatabaseName.forEach (function (databaseName) ... {... db =db.getSiblingDB (databaseName.name); ... collectionName =db.getCollectionNames (); ... collectionName.forEach (function ( collectionName) ... {... print (collectionName); ...}); ...});
Điều này sẽ tạo ra kết quả sau
clearingItemsInNestedArrayDemocustomIdDemodeleteRecordDemodocumentExistsOrNotDemofindAllExceptFromOneOrtwoDemomongoExportDemostartup_logarraySizeErrorDemobasicInformationDemocopyThisCollectionToSampleDatabaseDemodeleteAllRecordsDemodeleteDocumentsdeleteDocumentsDemodeleteSomeInformationdocumentWithAParticularFieldValueDemoemployeefindListOfIdsDemofindSubstringgetAllRecordsFromSourceCollectionDemogetElementWithMaxIdDemointernalArraySizeDemolargestDocumentDemomakingStudentInformationCloneoppositeAddToSetDemoprettyDemoreturnOnlyUniqueValuesDemoselectWhereInDemosourceCollectionstudentInformationsumOfValueDemotruncateDemoupdateInformationuserInformationcopyThisCollectionToSampleDatabaseDemodeleteDocumentsdeleteDocumentsDemodeleteInformationemployeeinternalArraySizeDemoprettyDemosourceCollectionupdateInformationuserInformationcol1col2indexingForArrayElementDemoremoveObjectFromArrayDemospecifyAKeyDemouseVariableDemoConvertStringToDateDemoEmployee_InformationIdUpdateDemoIndexingDemoNotAnd DemoProductsInformationaddCurrentDateTimeDemoaddFieldDemoaddNewFieldToEveryDocumentaggregateSumDemoaggregationFrameworkWithOrMatchDemoaggregationSortDemoandOrDemoarrayInnerElementsDemoarrayLengthGreaterThanOnearrayOfArraysDemoavoidDuplicateEntriesDemocaseInsensitiveDemocaseInsesitiveDemocastingDemochangeDataTypechangeTypecharactersAllowedDemocharactersDemocheckFieldContainsStringDemocheckFieldExistsOrNotDemocheckSequenceDemocollectionOnDifferentDocumentDemocombinationOfArrayDemocomparingTwoFieldsDemoconcatStringAndIntDemoconditionalSumDemoconvertStringToNumberDemocopyThisCollectionToSampleDatabaseDemocountDemocountPerformanceDemocreateSequenceDemocreatingUniqueIndexDemodateDemodeleteAllElementsInArrayDemodeleteRecordDemodemo.insertCollectiondistinctAggregationdistinctCountValuesDemodistinctRecordDemodistinctWithMultipleKeysDemodoubleNestedArrayDemoembeddedCollectionDemoemployeeInformationequivalentForSelectColumn1Column2DemofieldIsNullOrNotSetDemofilterArrayfindAllDuplicateKeyDocumentD emofindAllNonDistinctDemofindByMultipleArrayDemofindDocumentDoNotHaveCertainFieldsfindDocumentNonExistenceFieldDemofindDocumentWithObjectIdDemofindDuplicateByKeyDemofindDuplicateRecordsDemofindMinValueDemofindSpecificValuefindValueInArrayWithMultipleCriteriaDemofirstDocumentDemofirstItemInArrayToNewFieldDemogetDistinctListOfSubDocumentFieldDemogetFirstItemDemogetIndexSizeDemogetLastNRecordsDemogetLastXRecordsDemogetNThElementDemogetParticularElementFromArrayDemogetPartuclarElementgetSizeDemogetSizeOfArraygettingHighestValueDemogroupByDateDemohideidDemoidentifyLastDocuementDemoincrementValueDemoincrementValueInNestedArrayDemoindexDemoindexOptimizationDemoindexTimeDemoindex_DemoindexingDemoinsertDemoinsertFieldWithCurrentDateDemoinsertIfNotExistsDemoinsertIntegerDemoinsertOneRecordDemolistAllValuesOfCeratinFieldsDemomatchBetweenFieldsDemomongoExportDemomultipleOrDemomy-collectionnestedArrayDemonestedIndexDemonestedObjectDemonew_CollectionnotLikeOpeartorDemonumberofKeysInADocumentDemoobje ctInAnArrayDemoobjectidToStringDemoorConditionDemoorDemoorderDocsDemopaginationDemoperformRegexpriceStoredAsStringDemopriceStoredDemoqueryArrayElementsDemoqueryByKeyDemoqueryBySubFieldDemoqueryForBooleanFieldsDemoqueryInSameDocumentsDemoqueryToEmbeddedDocumentqueryingMongoDbCaseInsensitiveDemoregExpOnIntegerDemoregexSearchDemoremoveArrayDemoremoveArrayElementremoveArrayElementByItsIndexDemoremoveArrayElementsremoveDocumentOnBasisOfIdremoveDuplicateDocumentDemoremoveDuplicateDocumentsremoveElementFromDoublyNestedArrayDemoremoveFieldCompletlyDemoremoveMultipleDocumentsDemoremoveObjectremovingidElementDemorenameFieldDemoretrieveValueFromAKeyDemoretunFieldInFindDemoreturnQueryFromDatereverseRegexDemossearchArrayDemosearchDocumentDemosearchDocumentWithSpecialCharactersDemosearchMultipleFieldsDemosecondDocumentDemoselectInWhereIdDemoselectMongoDBDocumentsWithSomeConditionselectRecordsHavingKeyDemoselectSingleFieldDemosingleFieldDemosortDemosortInnerArrayDemosortingDemosourceCollectionsqlLike DemostringFieldLengthDemostringToObjectIdDemotest.jstranslateDefinitionDemounconditionalUpdatesDemouniqueIndexOnArrayDemounprettyJsonDemounwindOperatorDemoupdateDemoupdateDemounconditionalUpdatesDemouniqueIndexOnArrayDemounprettyJsonDemounwindOperatorDemoupdateDemoupdateDemounconditionalUpdatesDemounique