Largest and smallest documents: Difference between revisions
From NoSQLZoo
Created page with "<pre class=setup> #ENCODING import io import sys sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-16') #MONGO from pymongo import MongoClient client = MongoClien..." |
No edit summary |
||
| Line 7: | Line 7: | ||
from pymongo import MongoClient | from pymongo import MongoClient | ||
client = MongoClient() | client = MongoClient() | ||
client. | client.progzoo.authenticate('scott','tiger') | ||
db = client[' | db = client['progzoo'] | ||
#PRETTY | #PRETTY | ||
import pprint | import pprint | ||
| Line 26: | Line 26: | ||
big_doc = {} | big_doc = {} | ||
for x in db. | for x in db.world.find(): | ||
size = len(bson.BSON.encode(x)) | size = len(bson.BSON.encode(x)) | ||
if(size > biggest): | if(size > biggest): | ||
Revision as of 18:20, 26 July 2015
#ENCODING
import io
import sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-16')
#MONGO
from pymongo import MongoClient
client = MongoClient()
client.progzoo.authenticate('scott','tiger')
db = client['progzoo']
#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.world.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)