Saurabh Agrawal
Saurabh Agrawal

Reputation: 7739

database must be an instance of database pymongo

I am trying this

username1 = "admin"
password = "password"
host = "localhost"

prefix = 'mongodb://' + username1 + ':'
suffix =  '@' + host + ':27017/'
connString =  prefix + urllib.quote(password) + suffix
db = MongoClient(connString)
fs = gridfs.GridFS(db)//getting error at this line 

And the error is database must be an instance of database pymongo.

I am following this

Your help will be highly appreciated.

Upvotes: 2

Views: 1792

Answers (1)

Oluwafemi Sule
Oluwafemi Sule

Reputation: 38982

The misunderstanding here is a result of misnomer.

The following creates a connection.

connection = MongoClient(connString)

To get a pymongo.database object you can readily make one on the fly by accessing an inexistent field on the connection instance or one for a database that already exists.

db = connection.roundhouse # where roundhouse is the name for my database

Upvotes: 3

Related Questions