Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pprint import pprint
- import pymongo
- c = pymongo.Connection()
- col = c.test.mxscn
- def insert():
- print 'Inserting data...'
- col.drop()
- col.ensure_index([('nr', 1), ('ts', -1)])
- for i in xrange(50000):
- col.insert( { 'ts': i,
- 'nr': i % 47 } )
- def test(max_scan):
- spec = { 'ts': {'$gte': 0, '$lte': 100000}, 'nr': 43 }
- cursor = col.find(spec=spec, max_scan=max_scan).sort('ts', -1)
- results = list(cursor)
- print ' Found %s results for max_scan=%s (%s). \n' % (len(results), max_scan, spec)
- pprint(cursor.explain())
- print '=' * 80
- insert()
- test(100)
- test(101)
- test(200)
Add Comment
Please, Sign In to add comment