Neuro17
11/21/2013 - 10:44 AM

using_regexp.py

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