Largest and smallest documents
From NoSQLZoo
#ENCODING import io import sys sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-16') #MONGO from pymongo import MongoClient client = MongoClient() client.elite.authenticate('scott','tiger') db = client['elite'] #PRETTY import pprint pp = pprint.PrettyPrinter(indent=4) #CODE from bson.code import Code
import bson, sys biggest = 0 smallest = sys.maxsize small_doc = {} big_doc = {} for x in db.systems.find(): size = len(bson.BSON.encode(x)) if(size > biggest): biggest = size; small_doc = x if(size < smallest): smallest = size; big_doc = x pp.pprint(small_doc) pp.pprint(big_doc)