title: fast update in mongo db
body: <p>here's my problem. I want to make a collection in mongodb where I have a word and the number of the times it occurs. I'm doing it in python and it's extrememly slow. It's most probably because for every word that i have, I check if it is already in the database (using
  *find_one*)and if yes, get its frequency, increment it and store it back (using <em>update</em>) Of course, when the word is not there, I append it to a list and do bulk insert periodically.</p>
  
  <p>Is there a better way of doing this? The number of words is huge (different languages possible). Is mongoDB the right thing to use in the first place? I chose mongoDB because it was very easy to install to and I picked up the tutorial in 10 min...</p>
  
  <p><strong>edit</strong> - added the code as well. When I say large, I mean a file that is some 4 GB large with words in them...</p>
  
  <pre><code>insertlist = []
  
  def copy_to_db(word):
      global insertlist
  
      wordCollection = db['words']
      occurrence = wordCollection.find_one({'word' : word})
      if occurrence:
              n = occurrence['number']
              n = n + 1
              wordCollection.update({'word' : word}, {'$set' : {'number' : n}})
      else:
              insertlist.append({'word' : word, 'number' : 1})
              #wordCollection.insert({'word' : word, 'number' : 1})
  
      if len(insertlist) &gt;= 5000:
              print("insert triggered ... ")
              wordCollection.insert(insertlist)
              insertlist = []
  </code></pre>
  
  <p>i call this func. for every word.</p>