title: Converting pandas series to a list, is not working as input to Pymongo
body: <p>I have some data stored in a panda DataFrame and I would like to query my MongoDB with a list constructed from a single series in the DataFrame. When I convert the series with <code>.tolist()</code>  or the function <code>list()</code> I apparently get a list, but when I input this list in a Pymongo query I get the error:</p>
  
  <p><code>bson.errors.InvalidDocument: Cannot encode object: &lt;the first value of the list&gt;</code></p>
  
  <p><strong>Here is an example that reproduces the error:</strong></p>
  
  <p>So first creating a Mongo database:</p>
  
  <pre><code>from pymongo import MongoClient
  import pandas as pd
  
  db = MongoClient().test
  db.collection.insert_many([{'key_x':1},{'key_x':2},{'key_x':3}])
  </code></pre>
  
  <p>Then I query the database for the documents where <code>key_x</code> is in [1,3]:</p>
  
  <pre><code>x_list = [1,3]
  for doc in db.collection.find({'key_x':{'$in': x_list}}):
      print doc
  </code></pre>
  
  <p>As expected no error and the two entries <code>{'key_x':2}</code> and <code>{'key_x':3}</code> are printed to the console.</p>
  
  <p>Now I try first transforming the list to a Pandas series and converting back to a list.</p>
  
  <pre><code>ser = pd.Series([1,3])
  x_list = ser.tolist()
  
  print type(x_list) #Checking to see if it is indeed a list
  &gt; &lt;type 'list'&gt;
  
  for doc in db.collection.find({'key_x':{'$in': x_list}}):
      print doc
  </code></pre>
  
  <p>Then this error message is printed:</p>
  
  <pre><code>&gt;bson.errors.InvalidDocument: Cannot encode object: 1
  </code></pre>
  
  <p>Thank you very much for any input.</p>