2

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.

2
  • could you also show the imports? Commented Apr 3, 2018 at 5:04
  • 1
    You need to provide database to GridFS as shown in the example. Right now you db is a database connection. Use db = MongoClient(connString).my_collection Commented Apr 3, 2018 at 5:26

1 Answer 1

3

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
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.