破译连接到托管在 <project>.meteor.com 的 mongo 实例的错误 [英] Decipher an error connecting to a mongo instance hosted at <project>.meteor.com
问题描述
我想使用 python 连接到与在meteor.com 上托管的meteor 应用程序绑定的mongo 实例.我已经通过 meteor mongo -U
命令获得了我的应用程序的 URL,并且我能够连接.但是,当我建立连接并尝试做一些简单的事情(枚举幻灯片"集合中的文档)时,出现错误:
I'd like to use python to connect to an instance of mongo tied to a meteor app hosted at meteor.com. I've gotten the URL for my app via the meteor mongo -U <appname>
command, and I am able to connect. However, when I have gotten connected and try to do something simple (enumerate documents in the "slides" collection), I get an error:
In [1]: import pymongo
In [2]: con = pymongo.Connection("mongodb://client:f066d336-f5bd-1a85-1039-c679fbb645a1@skybreak.member0.mongolayer.com:27017/slides_meteor_com").meteor
In [3]: con.slides.find()
Out[3]: <pymongo.cursor.Cursor at 0x109873690>
In [4]: [ x for x in con.slides.find() ]
---------------------------------------------------------------------------
OperationFailure Traceback (most recent call last)
/Users/bensonk/Code/lfnw-elite-talk/<ipython-input-4-2112945d50ca> in <module>()
----> 1 [ x for x in con.slides.find() ]
/Library/Python/2.7/site-packages/pymongo/cursor.pyc in next(self)
701 raise StopIteration
702 db = self.__collection.database
--> 703 if len(self.__data) or self._refresh():
704 if self.__manipulate:
705 return db._fix_outgoing(self.__data.pop(0), self.__collection)
/Library/Python/2.7/site-packages/pymongo/cursor.pyc in _refresh(self)
664 self.__skip, ntoreturn,
665 self.__query_spec(), self.__fields,
--> 666 self.__uuid_subtype))
667 if not self.__id:
668 self.__killed = True
/Library/Python/2.7/site-packages/pymongo/cursor.pyc in __send_message(self, message)
626 response = helpers._unpack_response(response, self.__id,
627 self.__as_class,
--> 628 self.__tz_aware)
629 except AutoReconnect:
630 db.connection.disconnect()
/Library/Python/2.7/site-packages/pymongo/helpers.pyc in _unpack_response(response, cursor_id, as_class, tz_aware)
99 raise AutoReconnect("master has changed")
100 raise OperationFailure("database error: %s" %
--> 101 error_object["$err"])
102
103 result = {}
OperationFailure: database error: unauthorized db:meteor lock type:-1 client:173.160.192.81
据我所知,这是 mongo,表明我无权读取该集合.我可以通过 meteor mongo <projectname
从 mongo 控制台读取它,但不能从 python 读取.我如何在 python 中读取它?
From what I can tell, this is mongo suggesting I don't have access to read from that collection. I can read from it from a mongo console via meteor mongo <projectname
, but not from python. How can I read from it in python?
推荐答案
您的数据库似乎正在使用身份验证,而您尚未指定用户名/密码.在 python 中,这是通过 db.authenticate(username, password)
完成的.详情请见:http://api.mongodb.org/python/2.1.1/api/pymongo/database.html
It looks like your database is using authentication and you haven't specified a username/password. In python this is done with db.authenticate(username, password)
. Details here: http://api.mongodb.org/python/2.1.1/api/pymongo/database.html
这篇关于破译连接到托管在 <project>.meteor.com 的 mongo 实例的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!