Skip to content

Instantly share code, notes, and snippets.

@bchirico
Created November 21, 2013 10:44
Show Gist options
  • Save bchirico/7579546 to your computer and use it in GitHub Desktop.
Save bchirico/7579546 to your computer and use it in GitHub Desktop.
from pymongo import MongoClient
import sys
client = MongoClient('localhost', 27017)
db = client.reddit
stories = db.stories
def find():
print "find using regExp"
query = {'title': {'$regex': 'Google'}}
selector = {'title': 1, '_id':0}
try:
cursor = stories.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