解决连接到<project> .meteor.com </project>托管的mongo实例的错误

时间:2012-04-29 08:11:35

标签: python mongodb meteor

我想使用python连接到与meteor.com上托管的meteor应用程序绑定的mongo实例。我通过meteor mongo -U <appname>命令获取了我的应用程序的URL,并且我能够连接。但是,当我连接并尝试做一些简单的事情(枚举“幻灯片”集合中的文档)时,我收到一个错误:

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中读取它?

1 个答案:

答案 0 :(得分:1)

您的数据库似乎正在使用身份验证,而您尚未指定用户名/密码。在python中,这是使用db.authenticate(username, password)完成的。详情请见http://api.mongodb.org/python/2.1.1/api/pymongo/database.html