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
To connect to your local MongoDB, you set Hostname to localhost and Port to 27017 . These values are the default for all local MongoDB connections (unless you changed them). Press connect, and you should see the databases in your local MongoDB.
MongoDB is a document-oriented database classified as NoSQL. It's become popular throughout the industry in recent years and integrates extremely well with Python. Unlike traditional SQL RDBMSs, MongoDB uses collections of documents instead of tables of rows to organize and store data.
Without any arguments, the mongo command attempts to connect to a local MongoDB instance. To do this, it attempts to connect to port 27017 on the local loopback address: 127.0. 0.1:27017 .
Below are commands to create connection and query
from pymongo import MongoClient
client = MongoClient('hostname', 27017)
db = client.database_name
collection = db.collection_name
collection.find_one({"name":"name1"})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With