Collection object is not callable. If you meant to call the createCollection method on a Database object it is failing because no such method exists
I am having issues with mongoDB specifically when trying to create a collection.
I have imported pymongo and DNS they both work but when I try to create a collection using db.createCollection("verified")
, it would throw an error saying that 'Database' not an attribute of 'createCollection'
Here is the part of my code that involves MongoDB:
import pymongo
import dns
client = pymongo.MongoClient(myMongoDBconnectionURL)
db = client['MainDB']
db.createCollection("verified")
Do you know what is causing this?
Thanks
Solution 1:
I suspect that you are using the wrong MongoDB Documentation (as in, the documentation of a MongoDB implementation in a different programming language). createCollection
is not a method of pymongo.database.Database
, but create_collection
is:
import pymongo
import dns
client = pymongo.MongoClient(myMongoDBconnectionURL)
db = client['MainDB']
db.create_collection("verified")