如何从所有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
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短