error :document must be an instance of dict, bson.son.SON, bson.raw_bson.RawBSONDocument, or a type that inherits from collections.MutableMapping
<p>Tried to store twitter stream data into MongoDB. The code is pretty much a copy from <a href="http://stats.seandolinar.com/collecting-twitter-data-storing-tweets-in-mongodb/" rel="noreferrer">http://stats.seandolinar.com/collecting-twitter-data-storing-tweets-in-mongodb/</a>  but always show an error. If I tried to print out the data, it shown json file continuously grow, but it seems never ends in spite of the time limit for the while loop.!</p>

<pre><code>class listener(StreamListener):

    def __init__(self, start_time, time_limit=60):     
        self.time = start_time
        self.limit = time_limit

    def on_data(self, data):     
        while (time.time() - self.time) &lt; self.limit:    
            try:
                tweet = json.loads(data)
                client = MongoClient('localhost', 27017)
                db = client['twitter_db']
                collection = db['twitter_collection']
                collection.insert_many(tweet)
                return True
            except BaseException, e:
                print 'failed ondata,', str(e)
                time.sleep(5)
                pass
                exit()

    def on_error(self, status):
        print statuses
</code></pre>