Search code examples
pythonmongodbtwitterlinux-mint

MongoDB / Pymongo installed through Anaconda is not working on my system


I am using some scripts I found of Github to mine data from Twitter in Python. My machine is running on Linux Mint, fyi:

One of the scripts I'm using requires me to use MongoDB, which I don't know much about.

I successfully installed MongoDB and Pymongo through Anaconda as I like to use Anaconda as much as possible.

However, when I run my program that requires access to MongoDB, I get this error message:

localhost:27017: [Errno 111] Connection refused

The advice I see online (such as from this thread) instructs me to remove the lock on MongoDB or repair it or start it, or check the status, but I just get responses that MongoDB is not on my system, like this:

   Loaded: not-found (Reason: No such file or directory)

Is there a way to run MongoDB through Anaconda and get it to work for my purposes, or do I need to install it on my system?


Solution

  • When I was using mongodb and pymongo for managing data collected from twitter on my machine, it's really straightforward.

    1. Install mongodb according to instructions on the official website of MongoDB
    2. Run mongodb on your machine with command

      mongod

    3. Test if you can connect mongodb with command

      mongo

    4. Code with pymongo

      from pymongo import MongoClient client = MongoClient() records = client.twitter.posts.find({}, {"_id": 0, "message": 1, "comments.message": 1}).limit(10).limit(10)