title: MongoDB field value to variable in python
body: <p>I am taking entries from MongoDB and I want to do some modifications, data crunching etc and updating. In this particular example Iam trying for every document in collection
   <code>{u'time': 1405694995.310651, u'text': u'HOHO,r\u012bt ar evitu uz positivus ar vip bi\u013ceti kabat\u0101:)', u'_id': ObjectId('53cd621d51f4fbe9f6e04da4'), u'name': u'Madara  B\u013cas\u0101ne', u'screenName': u'miumiumadara'}</code> take its text value as a string, count its keyword values and after add to exact particular document field with keyword value. </p>
  
  <p>I am struggling with taking text field as string so it can be operated. And also I havent found solution in python how to add new field to document with count variable. In a Mongo shell comands are easy, but here i dont know. Anything for me to look for?</p>
  
  <pre><code>db = conn.posit2014
  collection = db.ceturtdiena
  
      cursor = db.all.find()
      for text_fromDB in cursor:
  
          print text_fromDB
  
          source_text = text_fromDB.translate(None, '#!@£$%^&amp;*()_:""?&gt;&lt;.,/\|+-')
          source_text = source_text.lower()
  
          source_words = source_text.split()
  
          count = 0  
          word_list = []
          with open('pozit.txt') as inputfile:
              for line in inputfile:
                  word_list.append(line.strip())
  
          for word in word_list:
              if word in source_words:
                  count += 1
  
          #add count variable to each document
          # {$set : {value:'count'}}
  </code></pre>