0

I wrote the below code in Pycharm.

import pymongo
from pymongo import mongo_client
connection = mongo_client()

When I executed the code, I got the below error.

Traceback (most recent call last): File "C:/Users/Mohan/PycharmProjects/pymongo/mongotutorial.py", line 7, in connection = mongo_client() TypeError: 'module' object is not callable.

My Python version is 3.6.5. Can you please help?

1
  • Did you install pymongo? You can install the module with pip install pymongo Commented Oct 20, 2018 at 20:12

1 Answer 1

1

Try this code below:

from pymongo import MongoClient

client = MongoClient()
client = MongoClient('localhost', 27017)
db = client['test-database'] # or db = client.test_database
collection = db['test-collection'] # or collection = db.test_collection

Hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.