Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> MongoDB

จะรับคอลเล็กชันทั้งหมดจากฐานข้อมูล 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 , "ว่าง" :false }]

ต่อไปนี้เป็นแบบสอบถามเพื่อรับชื่อคอลเลกชันทั้งหมดจากฐานข้อมูล

<ก่อนหน้า>> allDatabaseName.forEach(function(databaseName)... {... db =db.getSiblingDB(databaseName.name);... collectionName =db.getCollectionNames();... collectionName.forEach(function() collectionName)... {... print(collectionName);... });... });

สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้

 clearingItemsInNestedArrayDemocustomIdDemodeleteRecordDemodocumentExistsOrNotDemofindAllExceptFromOneOrtwoDemomongoExportDemostartup_logarraySizeErrorDemobasicInformationDemocopyThisCollectionToSampleDatabaseDemodeleteAllRecordsDemodeleteDocumentsdeleteDocumentsDemodeleteSomeInformationdocumentWithAParticularFieldValueDemoemployeefindListOfIdsDemofindSubstringgetAllRecordsFromSourceCollectionDemogetElementWithMaxIdDemointernalArraySizeDemolargestDocumentDemomakingStudentInformationCloneoppositeAddToSetDemoprettyDemoreturnOnlyUniqueValuesDemoselectWhereInDemosourceCollectionstudentInformationsumOfValueDemotruncateDemoupdateInformationuserInformationcopyThisCollectionToSampleDatabaseDemodeleteDocumentsdeleteDocumentsDemodeleteInformationemployeeinternalArraySizeDemoprettyDemosourceCollectionupdateInformationuserInformationcol1col2indexingForArrayElementDemoremoveObjectFromArrayDemospecifyAKeyDemouseVariableDemoConvertStringToDateDemoEmployee_InformationIdUpdateDemoIndexingDemoNotAnd DemoProductsInformationaddCurrentDateTimeDemoaddFieldDemoaddNewFieldToEveryDocumentaggregateSumDemoaggregationFrameworkWithOrMatchDemoaggregationSortDemoandOrDemoarrayInnerElementsDemoarrayLengthGreaterThanOnearrayOfArraysDemoavoidDuplicateEntriesDemocaseInsensitiveDemocaseInsesitiveDemocastingDemochangeDataTypechangeTypecharactersAllowedDemocharactersDemocheckFieldContainsStringDemocheckFieldExistsOrNotDemocheckSequenceDemocollectionOnDifferentDocumentDemocombinationOfArrayDemocomparingTwoFieldsDemoconcatStringAndIntDemoconditionalSumDemoconvertStringToNumberDemocopyThisCollectionToSampleDatabaseDemocountDemocountPerformanceDemocreateSequenceDemocreatingUniqueIndexDemodateDemodeleteAllElementsInArrayDemodeleteRecordDemodemo.insertCollectiondistinctAggregationdistinctCountValuesDemodistinctRecordDemodistinctWithMultipleKeysDemodoubleNestedArrayDemoembeddedCollectionDemoemployeeInformationequivalentForSelectColumn1Column2DemofieldIsNullOrNotSetDemofilterArrayfindAllDuplicateKeyDocumentD emofindAllNonDistinctDemofindByMultipleArrayDemofindDocumentDoNotHaveCertainFieldsfindDocumentNonExistenceFieldDemofindDocumentWithObjectIdDemofindDuplicateByKeyDemofindDuplicateRecordsDemofindMinValueDemofindSpecificValuefindValueInArrayWithMultipleCriteriaDemofirstDocumentDemofirstItemInArrayToNewFieldDemogetDistinctListOfSubDocumentFieldDemogetFirstItemDemogetIndexSizeDemogetLastNRecordsDemogetLastXRecordsDemogetNThElementDemogetParticularElementFromArrayDemogetPartuclarElementgetSizeDemogetSizeOfArraygettingHighestValueDemogroupByDateDemohideidDemoidentifyLastDocuementDemoincrementValueDemoincrementValueInNestedArrayDemoindexDemoindexOptimizationDemoindexTimeDemoindex_DemoindexingDemoinsertDemoinsertFieldWithCurrentDateDemoinsertIfNotExistsDemoinsertIntegerDemoinsertOneRecordDemolistAllValuesOfCeratinFieldsDemomatchBetweenFieldsDemomongoExportDemomultipleOrDemomy-collectionnestedArrayDemonestedIndexDemonestedObjectDemonew_CollectionnotLikeOpeartorDemonumberofKeysInADocumentDemoobje ctInAnArrayDemoobjectidToStringDemoorConditionDemoorDemoorderDocsDemopaginationDemoperformRegexpriceStoredAsStringDemopriceStoredDemoqueryArrayElementsDemoqueryByKeyDemoqueryBySubFieldDemoqueryForBooleanFieldsDemoqueryInSameDocumentsDemoqueryToEmbeddedDocumentqueryingMongoDbCaseInsensitiveDemoregExpOnIntegerDemoregexSearchDemoremoveArrayDemoremoveArrayElementremoveArrayElementByItsIndexDemoremoveArrayElementsremoveDocumentOnBasisOfIdremoveDuplicateDocumentDemoremoveDuplicateDocumentsremoveElementFromDoublyNestedArrayDemoremoveFieldCompletlyDemoremoveMultipleDocumentsDemoremoveObjectremovingidElementDemorenameFieldDemoretrieveValueFromAKeyDemoretunFieldInFindDemoreturnQueryFromDatereverseRegexDemossearchArrayDemosearchDocumentDemosearchDocumentWithSpecialCharactersDemosearchMultipleFieldsDemosecondDocumentDemoselectInWhereIdDemoselectMongoDBDocumentsWithSomeConditionselectRecordsHavingKeyDemoselectSingleFieldDemosingleFieldDemosortDemosortInnerArrayDemosortingDemosourceCollectionsqlLike Demostring ฟิลด์ความยาว Demostring ไปที่ObjectIdDemotest.jstranslate Definition Demounconditional อัพเดต Demonique ดัชนี On Array Demounpretty Json Demounwind Operator Demoupdate Demoupdate ExactFieldupdate ID Demoupdate เอกสารจำนวนมาก Demoupdate ซ้อนกัน ค่าสถานะ Demoupdate วัตถุ