PyMongo Collection Object Not Callable
Question: I'm trying to create a reddit scraper that takes the first 100 pages from the
reddit home page and stores them into MongoDB. This is my first post on
stackoverflow, so I apologize if my post is not formatted correctly. I keep
getting the error:

    
    
    TypeError: 'Collection' object is not callable. If you meant to call the 'insert_one' method on a 'Collection' object it is failing because no such method exists.
    

Here is my code

    
    
    import pymongo
    import praw
    import time
    
    
    def main():
        fpid = os.fork()
        if fpid!=0:
            # Running as daemon now. PID is fpid
            sys.exit(0)
    
        user_agent = ("Python Scraper by djames v0.1")
        r = praw.Reddit(user_agent = user_agent)    #Reddit API requires user agent
    
        conn=pymongo.MongoClient()
        db = conn.reddit
        threads = db.threads
    
    
        while 1==1:    #Runs in an infinite loop, loop repeats every 30 seconds
            frontpage_pull = r.get_front_page(limit=100)    #get first 100 posts from reddit.com
    
            for posts in frontpage_pull:    #repeats for each of the 100 posts pulled
                data = {}
                data['title'] = posts.title
                data['text'] = posts.selftext
                threads.insert_one(data)
            time.sleep(30)
    
    if __name__ == "__main__":
        main()
    


Answer: `insert_one()` was not added to pymongo until version 3.0. If you try calling
it on a version before that, you will get the error you are seeing.

To check you version of pymongo, open up a python interpreter and enter:

    
    
    import pymongo
    pymongo.version
    

The legacy way of inserting documents with pymongo is just with
`Collection.insert()`. So in your case you can change your insert line to:

    
    
    threads.insert(data)
    

For more info, see [pymongo 2.8
documentation](https://api.mongodb.org/python/2.8/api/pymongo/collection.html?highlight=insert#pymongo.collection.Collection.insert)

