0

我想使用 python 连接到一个绑定到流星应用程序的 mongo 实例,该流星应用程序托管在meteor.com。我已经通过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 建议我无权读取该集合。我可以通过 mongo 控制台读取它meteor mongo <projectname,但不能从 python 读取。如何在 python 中读取它?

4

1 回答 1

1

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

于 2012-04-30T14:53:24.993 回答