Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (4k points)

I am using ipython 2.7. I am creating database name enron in mongodb. I have tried to connect to this database locally but the following error occurred - how do I fix it?

this my code:

import json
import pymongo  # pip install pymongo
from bson import json_util 
from pymongo import MongoClient# Comes with pymongo
conn = pymongo.Connection('mongodb://user:[email protected]:33499/enron')
client = MongoClient()

error:

ConnectionFailure: could not connect to localhost:27017: [Errno 10061] No connection     could be made because the target machine actively refused it

1 Answer

0 votes
by (8.7k points)

Run the below mentioned commands:

from pymongo import MongoClient

client = MongoClient('hostname', 27017)

db = client.database_name

collection = db.collection_name

collection.find_one({"name":"name1"})

want to learn MongoDB, check out the MongoDB tutorial by Intellipaat.

Browse Categories

...