Computer >> 컴퓨터 >  >> 프로그램 작성 >> MongoDB

모든 MongoDB 데이터베이스에서 모든 컬렉션을 가져오는 방법은 무엇입니까?

<시간/>

모든 데이터베이스에서 모든 컬렉션을 가져오려면 먼저 다음 쿼리를 사용하여 모든 데이터베이스를 가져옵니다.

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

그러면 다음과 같은 출력이 생성됩니다.

[ { "이름" :"관리자", "sizeOnDisk" :495616, "빈" :false }, { "이름" :"config", "sizeOnDisk" :98304, "빈" :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 , "비어 있음" :거짓 }]

다음은 데이터베이스에서 모든 컬렉션 이름을 가져오는 쿼리입니다.

> allDatabaseName.forEach(function(databaseName)... {... db =db.getSiblingDB(databaseName.name);... collectionName =db.getCollectionNames();... collectionName.forEach(function( 컬렉션 이름)... {... print(컬렉션 이름);... });... });

그러면 다음과 같은 출력이 생성됩니다.

clearingItemsInNestedArrayDemocustomIdDemodeleteRecordDemodocumentExistsOrNotDemofindAllExceptFromOneOrtwoDemomongoExportDemostartup_logarraySizeErrorDemobasicInformationDemocopyThisCollectionToSampleDatabaseDemodeleteAllRecordsDemodeleteDocumentsdeleteDocumentsDemodeleteSomeInformationdocumentWithAParticularFieldValueDemoemployeefindListOfIdsDemofindSubstringgetAllRecordsFromSourceCollectionDemogetElementWithMaxIdDemointernalArraySizeDemolargestDocumentDemomakingStudentInformationCloneoppositeAddToSetDemoprettyDemoreturnOnlyUniqueValuesDemoselectWhereInDemosourceCollectionstudentInformationsumOfValueDemotruncateDemoupdateInformationuserInformationcopyThisCollectionToSampleDatabaseDemodeleteDocumentsdeleteDocumentsDemodeleteInformationemployeeinternalArraySizeDemoprettyDemosourceCollectionupdateInformationuserInformationcol1col2indexingForArrayElementDemoremoveObjectFromArrayDemospecifyAKeyDemouseVariableDemoConvertStringToDateDemoEmployee_InformationIdUpdateDemoIndexingDemoNotAnd를
 DemoProductsInformationaddCurrentDateTimeDemoaddFieldDemoaddNewFieldToEveryDocumentaggregateSumDemoaggregationFrameworkWithOrMatchDemoaggregationSortDemoandOrDemoarrayInnerElementsDemoarrayLengthGreaterThanOnearrayOfArraysDemoavoidDuplicateEntriesDemocaseInsensitiveDemocaseInsesitiveDemocastingDemochangeDataTypechangeTypecharactersAllowedDemocharactersDemocheckFieldContainsStringDemocheckFieldExistsOrNotDemocheckSequenceDemocollectionOnDifferentDocumentDemocombinationOfArrayDemocomparingTwoFieldsDemoconcatStringAndIntDemoconditionalSumDemoconvertStringToNumberDemocopyThisCollectionToSampleDatabaseDemocountDemocountPerformanceDemocreateSequenceDemocreatingUniqueIndexDemodateDemodeleteAllElementsInArrayDemodeleteRecordDemodemo.insertCollectiondistinctAggregationdistinctCountValuesDemodistinctRecordDemodistinctWithMultipleKeysDemodoubleNestedArrayDemoembeddedCollectionDemoemployeeInformationequivalentForSelectColumn1Column2DemofieldIsNullOrNotSetDemofilterArrayfindAllDuplicateKeyDocumentD emofindAllNonDistinctDemofindByMultipleArrayDemofindDocumentDoNotHaveCertainFieldsfindDocumentNonExistenceFieldDemofindDocumentWithObjectIdDemofindDuplicateByKeyDemofindDuplicateRecordsDemofindMinValueDemofindSpecificValuefindValueInArrayWithMultipleCriteriaDemofirstDocumentDemofirstItemInArrayToNewFieldDemogetDistinctListOfSubDocumentFieldDemogetFirstItemDemogetIndexSizeDemogetLastNRecordsDemogetLastXRecordsDemogetNThElementDemogetParticularElementFromArrayDemogetPartuclarElementgetSizeDemogetSizeOfArraygettingHighestValueDemogroupByDateDemohideidDemoidentifyLastDocuementDemoincrementValueDemoincrementValueInNestedArrayDemoindexDemoindexOptimizationDemoindexTimeDemoindex_DemoindexingDemoinsertDemoinsertFieldWithCurrentDateDemoinsertIfNotExistsDemoinsertIntegerDemoinsertOneRecordDemolistAllValuesOfCeratinFieldsDemomatchBetweenFieldsDemomongoExportDemomultipleOrDemomy-collectionnestedArrayDemonestedIndexDemonestedObjectDemonew_CollectionnotLikeOpeartorDemonumberofKeysInADocumentDemoobje ctInAnArrayDemoobjectidToStringDemoorConditionDemoorDemoorderDocsDemopaginationDemoperformRegexpriceStoredAsStringDemopriceStoredDemoqueryArrayElementsDemoqueryByKeyDemoqueryBySubFieldDemoqueryForBooleanFieldsDemoqueryInSameDocumentsDemoqueryToEmbeddedDocumentqueryingMongoDbCaseInsensitiveDemoregExpOnIntegerDemoregexSearchDemoremoveArrayDemoremoveArrayElementremoveArrayElementByItsIndexDemoremoveArrayElementsremoveDocumentOnBasisOfIdremoveDuplicateDocumentDemoremoveDuplicateDocumentsremoveElementFromDoublyNestedArrayDemoremoveFieldCompletlyDemoremoveMultipleDocumentsDemoremoveObjectremovingidElementDemorenameFieldDemoretrieveValueFromAKeyDemoretunFieldInFindDemoreturnQueryFromDatereverseRegexDemossearchArrayDemosearchDocumentDemosearchDocumentWithSpecialCharactersDemosearchMultipleFieldsDemosecondDocumentDemoselectInWhereIdDemoselectMongoDBDocumentsWithSomeConditionselectRecordsHavingKeyDemoselectSingleFieldDemosingleFieldDemosortDemosortInnerArrayDemosortingDemosourceCollectionsqlLike DemostringFieldLengthDemostringToObjectIdDemotest.jstranslateDefinitionDemounconditionalUpdatesDemouniqueIndexOnArrayDemounprettyJsonDemounwindOperatorDemoupdateDemoupdateExactFieldupdateIdDemoupdateManyDocumentsDemoupdateNestedValueDemoupdateObjectsupdatingStatuseddedDocument