Skip to content

Instantly share code, notes, and snippets.

@tamr
Created June 14, 2017 21:57
Show Gist options
  • Save tamr/5932b7f19ac9cf30e6f81968f13b10a5 to your computer and use it in GitHub Desktop.
Save tamr/5932b7f19ac9cf30e6f81968f13b10a5 to your computer and use it in GitHub Desktop.
# -*- coding: UTF-8 -*-
from pymongo import *
import json,sys
def mongo_get(hosts):
client = MongoClient(hosts, 27017)
dbs = client.database_names()
for db in dbs:
mydb = client[db]
cols = mydb.collection_names()
for col in cols:
book = mydb[col]
print '---------------------------------------------------------------------'
print 'DB:'+db+'----'+'Collections:'+col
cont = str(book.find_one())
print cont.decode('unicode_escape')
print 'Number:'+str(book.find().count())
mongo_get(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment