Neuro17
11/21/2013 - 10:45 AM

using-dot_notation.py

from pymongo import MongoClient
import sys


client = MongoClient('localhost', 27017)

db = client.reddit
stories = db.stories

def find():
	print "find using dot notation"
	query = {'media.oembed.type': 'video'}
	selector = {'media.oembed.url': 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