MongoDB
 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 DemostringFieldLengthDemostringToObjectIdDemotest.jstranslateDefinitionDemounconditionalUpdatesDemouniqueIndexOnArrayDemounprettyJsonDemounwindOperatorDemoupdateDemoupdateExactFieldupdateIdDemoupdateManyDocumentsDemoupdateNestedValueDemoupdateObjectsupdatingEmbeddedDocumentPropertyDemouserStatus
  1. Matplotlibのプロットからすべての凡例を取得するにはどうすればよいですか?

    matplotlibのプロットからすべての凡例を取得するには、 get_children()を使用できます。 軸のすべてのプロパティを取得し、すべてのプロパティを反復するメソッド。アイテムが凡例のインスタンスである場合は、凡例のテキストを取得します。 ステップ 図のサイズを設定し、サブプロット間およびサブプロットの周囲のパディングを調整します。 numpyを使用してx個のデータポイントを作成します。 図とサブプロットのセットを作成します。 sin(x)をプロットします およびcos(x) plot()を使用する ラベルと色が異なる方法。 軸の子を取得し、凡例の

  2. Python辞書からすべてのキーのリストを取得するにはどうすればよいですか?

    辞書からすべてのキーのリストを取得するには、dict.keys()関数を使用するだけです。 例 my_dict = {'name': 'TutorialsPoint', 'time': '15 years', 'location': 'India'} key_list = list(my_dict.keys()) print(key_list) 出力 これにより、出力が得られます- ['name', 'time', 'location'] リスト内