Skip to content

Instantly share code, notes, and snippets.

@bchirico
Created November 21, 2013 10:42
Show Gist options
  • Save bchirico/7579524 to your computer and use it in GitHub Desktop.
Save bchirico/7579524 to your computer and use it in GitHub Desktop.
from pymongo import MongoClient
import sys
client = MongoClient('localhost', 27017)
db = client.school
score = db.score
def find():
print "command find with selector"
query = {'type': 'exam'}
selector = {'student_id': 1, '_id': 0} #mostra nel risultato il campo student_id e nasconde il campo _id
try:
cursor = score.find(query, selector)
except:
print "Unexpected error", sys.exc_info()[0]
limit = 0
for doc in cursor:
print doc
limit += 1
if (limit > 10):
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment