pymongo和VERSION中不存在FIND方法?

时间:2012-09-13 09:15:31

标签: python pymongo

我正在尝试用我的pymongo和一个临时数据库做一些简单的事情。所以第一件事就像往常一样

import pymongo
connection = pymongo.Connection(host = 'mongodb://username:password@alaki-staging.member0.mongolayer.com:37017,/dbname?safe=true&slaveOk=true&fsync=true&journal=true&ssl=true')

现在只是

connection.find({})
> Traceback (most recent call last):
  File "D:\MypythonCode\test.py", line 7, in <module>
    connection.find({})
  File "C:\Python27\lib\site-packages\pymongo\database.py", line 769, in __call_
_
    self.__name, self.__connection.__class__.__name__))
TypeError: 'Database' object is not callable. If you meant to call the 'find' me
thod on a 'Connection' object it is failing because no such method exists.

C:\Python27>python.exe D:\MypythonCode\test.py > test.d
Traceback (most recent call last):
  File "D:\MypythonCode\test.py", line 7, in <module>
    connection.find({})
  File "C:\Python27\lib\site-packages\pymongo\database.py", line 769, in __call_
_
    self.__name, self.__connection.__class__.__name__))
TypeError: 'Database' object is not callable. If you meant to call the 'find' me
thod on a 'Connection' object it is failing because no such method exists.

甚至检查版本!?

connection.version()

Traceback (most recent call last):
  File "test.py", line 7, in <module>
    connection.version()
  File "C:\Python27\lib\site-packages\pymongo\database.py", line 769, in __call_
_
    self.__name, self.__connection.__class__.__name__))
TypeError: 'Database' object is not callable. If you meant to call the 'version'
 method on a 'Connection' object it is failing because no such method exists.
Press any key to continue . . .

任何建议?!

1 个答案:

答案 0 :(得分:-1)

为什么要

connection.find({}) 

工作?

您在猜测API方法时没有阅读有关MongoDB和PyMongo的基础知识。

find()显然是一个集合的方法,而不是连接的方法。

row = connection.your_collection.find()

就是你的意思。

请在修补和猜测如何使用API​​之前阅读文档。

PyMongo文档中有很多例子。