Skip to content

Instantly share code, notes, and snippets.

@bchirico
Created November 21, 2013 10:46
Show Gist options
  • Save bchirico/7579577 to your computer and use it in GitHub Desktop.
Save bchirico/7579577 to your computer and use it in GitHub Desktop.
import pymongo
import sys
client = pymongo.MongoClient('localhost', 27017)
db = client.school
scores = db.score
def find():
print "find using dot notation"
query = {}
selector = {'media.oembed.url': 1, '_id':0}
try:
# cursor = scores.find(query).sort('student_id', pymongo.ASCENDING).skip(4).limit(5)
cursor = scores.find(query).sort([('student_id', pymongo.ASCENDING), ('scores', pymongo.DESCENDING)]).limit(10)
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