title: PyMongo Cursor Iteration
body: <p>I'm looking to create and handle a cursor in python the way cursors natively work in mongo. I know the intended way is to do 'result = collection.find()' and do a 'for record in result' but I'm looking to wrap iteration functionality in a class. I'd like to be able to create a new class object and call a function e.g. init_cursor() to make a db connection and do a find returning a cursor. I would then like the have a get_next() function that would move to the next result and set class data members based on the result. Here's the pesudo-code:</p>
  
  <pre><code>class dataIter():
      def __init__(self):
          self.collection = pymongo.Connection().db.collection
          self.cursor = self.collection.find({}) #return all
          self.age = None
          self.gender = None
  
      def get_next(self):
          if self.cursor.hasNext():
              data = self.cursor.next()
              self.set_data(data)
  
      def set_data(self, data):
          self.age = data['age']
          self.gender = data['gender']
  </code></pre>
  
  <p>This way I would be able to simply call:</p>
  
  <pre><code>obj.get_next()
  age = obj.age
  gender = obj.gender
  </code></pre>
  
  <p>or some other help functions to pull data out of each document</p>