Last active
August 29, 2015 14:17
-
-
Save masudak/b10cb7abd2acf6b38860 to your computer and use it in GitHub Desktop.
count collections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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