Cookies help us deliver our services. By using our services, you agree to our use of cookies. More information

Difference between revisions of "Largest and smallest documents"

From NoSQLZoo
Jump to: navigation, search
(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...")
 
 
(One intermediate revision by the same user not shown)
Line 7: Line 7:
 
from pymongo import MongoClient
 
from pymongo import MongoClient
 
client = MongoClient()
 
client = MongoClient()
client.elite.authenticate('scott','tiger')
+
client.progzoo.authenticate('scott','tiger')
db = client['elite']
+
db = client['progzoo']
 
#PRETTY
 
#PRETTY
 
import pprint
 
import pprint
Line 23: Line 23:
 
biggest = 0
 
biggest = 0
 
smallest = sys.maxsize
 
smallest = sys.maxsize
 +
big_doc = {}
 
small_doc = {}
 
small_doc = {}
big_doc = {}
 
  
for x in db.systems.find():
+
for x in db.world.find():
 
     size = len(bson.BSON.encode(x))
 
     size = len(bson.BSON.encode(x))
 
     if(size > biggest):
 
     if(size > biggest):
 
         biggest = size;
 
         biggest = size;
         small_doc = x
+
         big_doc = x
 
     if(size < smallest):
 
     if(size < smallest):
 
         smallest = size;
 
         smallest = size;
         big_doc = x
+
         small_doc = x
  
 +
pp.pprint(big_doc)
 
pp.pprint(small_doc)
 
pp.pprint(small_doc)
pp.pprint(big_doc)
 
 
</pre>
 
</pre>
 
</div>
 
</div>

Latest revision as of 18:29, 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
big_doc = {}
small_doc = {}

for x in db.world.find():
    size = len(bson.BSON.encode(x))
    if(size > biggest):
        biggest = size;
        big_doc = x
    if(size < smallest):
        smallest = size;
        small_doc = x

pp.pprint(big_doc)
pp.pprint(small_doc)