0

Python を使用して、meteor.com でホストされている流星アプリに関連付けられた 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 であり、そのコレクションから読み取るアクセス権がないことを示唆しています。を介して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 に答える