Skip to content

Instantly share code, notes, and snippets.

@masudak
Last active August 29, 2015 14:17
Show Gist options
  • Save masudak/b10cb7abd2acf6b38860 to your computer and use it in GitHub Desktop.
Save masudak/b10cb7abd2acf6b38860 to your computer and use it in GitHub Desktop.
count collections
#!/usr/bin/env python
from pymongo import Connection
connection = Connection('localhost', 27017)
def get_db_names():
return connection.database_names()
def get_collection_names(db_name):
print '====================================='
print 'DB: %s' % db_name
__db = connection[db_name]
return __db.collection_names()
def main():
for __db_name in get_db_names():
__collecions = get_collection_names(__db_name)
for __collection_name in __collecions:
__collection_count = connection[__db_name][__collection_name].count()
print 'TARGET COLLECTION: %s, COUNT: %s' % (__collection_name, __collection_count)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment