def getTableList(uri, internalTables=False, **kwargs):
"""
Get a list of known databases, each of which has a list of known
collections from the database. This is of the form [{'database':
(database 1), 'tables': [{'table': (collection 1)}, {'table':
(collection 2)}, ...]}, {'database': (database 2), 'tables': [...]},
...]
:param uri: uri to connect to the database.
:param internaltables: True to return tables about the database itself.
Ignored for Mongo.
:returns: A list of known collections.
"""
conn = MongoClient(uri)
databaseName = base.databaseFromUri(uri)
if databaseName is None:
databaseNames = conn.database_names()
else:
databaseNames = [databaseName]
results = []
for name in databaseNames:
database = conn[name]
results.append({
'database': name,
'tables': [{'table': collection, 'name': collection}
for collection in database.collection_names(False)]
})
return results
评论列表
文章目录