title: Python / Pymongo variable for collection name in db insert command
body: <p>I have this small piece of code that basically takes a list and runs a loop, running search queries against twitter, for each item in the list. I want each item in the list to be a collection name but for some reason I can't figure out how to make <code>db&lt;collection_name_variable&gt;.insert(post)&gt;</code> to actually work:</p>
  
  <p>I get an error:</p>
  
  <blockquote>
    <p>TypeError: unsupported operand type(s) for +: 'Database' and 'str'</p>
  </blockquote>
  
  <p>I know this is probably very basic but I am just learning.</p>
  
  <pre><code>from twython import Twython
  from pymongo import *
  
  conn = Connection('localhost')
  db = conn.nosqltweets
  twitter = Twython()
  
  types = ['mongodb', 'cassandra', 'couchdb']
  
  for nosql in types:
      search_results = twitter.searchTwitter(q=nosql, rpp="100")
      for tweet in search_results["results"]:
          from_user = tweet['from_user'].encode('utf-8')
          text = tweet['text']
          created_at = tweet['created_at']
          id_str = tweet['id_str']
          post = { 'id_str': id_str, 'from_user': from_user, 'created_at': created_at }
          insert = db + nosql + ".insert(post)"
          insert
  </code></pre>