Skip to content

Instantly share code, notes, and snippets.

@fmasanori
Last active December 19, 2015 08:08
Show Gist options
  • Save fmasanori/5923130 to your computer and use it in GitHub Desktop.
Save fmasanori/5923130 to your computer and use it in GitHub Desktop.
query3 mongo.py
import pymongo
import sys
connection = pymongo.MongoClient("mongodb://localhost")
db = connection.school
scores = db.scores
def find():
query = {'type': 'exam', 'score':{'$gt':50, '$lt':70}}
selector = {'student_id': 1, 'score':1, '_id': 0}
try:
cursor = scores.find(query, selector)
except:
print 'Unexpected error:', sys.exc_info()[0]
sanity = 0
for doc in cursor:
print doc
sanity += 1
if sanity > 10:
break
find()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment