mohan
mohan

Reputation: 1

mongo_client TypeError: 'module' object is not callable

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?

Upvotes: 0

Views: 1975

Answers (1)

Mark
Mark

Reputation: 6394

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.

Upvotes: 1

Related Questions