daily pastebin goal
90%
SHARE
TWEET

Untitled

a guest Jan 19th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from pprint import pprint
  2.  
  3. import pymongo
  4.  
  5. c = pymongo.Connection()
  6. col = c.test.mxscn
  7.  
  8. def insert():
  9.   print 'Inserting data...'
  10.   col.drop()
  11.   col.ensure_index([('nr', 1), ('ts', -1)])
  12.  
  13.   for i in xrange(50000):
  14.     col.insert( { 'ts': i,
  15.                   'nr': i % 47 } )
  16.  
  17. def test(max_scan):
  18.   spec = { 'ts': {'$gte': 0, '$lte': 100000}, 'nr': 43 }
  19.   cursor = col.find(spec=spec, max_scan=max_scan).sort('ts', -1)
  20.   results = list(cursor)
  21.  
  22.   print '   Found %s results for max_scan=%s (%s). \n' % (len(results), max_scan, spec)
  23.   pprint(cursor.explain())
  24.   print '=' * 80
  25.  
  26. insert()
  27. test(100)
  28. test(101)
  29. test(200)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top