So I'm trying to use PyMongo to connect to and manipulate a Mongo database.
I have the following code:
from pymongo import MongoClient
def mongo_uri():
return 'mongodb://username:password@ somewhere.mongolayer.com: 10011/my_app'
def my_db():
return MongoClient(mongo_uri()).my_db
When I call `db = my_db()` I get a `pymongo.database.Database` object with the correct name. So something is working correctly.
However, when I try to call `db.show_collections()` I get an error:
OperationFailure: database error: not authorized for query on my_db.system.namespaces
What am I doing wrong?
What permissions do you have on the database? Btw, what version is this?
I was using version 2.4.10 but just upgraded to version 2.6.5. I'm running Mongo in the cloud using Compose.io -- it was an addon through Heroku.
I don't know what permissions I have on the database. I guess I would have assumed I had all permissions, since I'm just connecting through the credentials that were set up for me when I created the addon in Heroku.
I can connect using "mongo" at the terminal command line as well, but I get the "not authorized" error when I try to run commands such as "show collections" or "show users".
I can run the command "use my_db" successfully, but apparently this is slightly misleading, since I can type anything at all in place of "my_db" and it will report that it is now using that db.
Basically, I can do nothing except connect with the right name and password. Giving the wrong name and password prevents me from connecting entirely, so I know that at least something is going through when I use the right name and password. From that point on, however, I can't run any command except "help".
Nevermind -- I didn't realize that my database was given a different name in my production cloud instance compared to my dev instance :(
댓글 없음:
댓글 쓰기