2012-09-13 45 views
1

我想用我的pymongo做臨時數據庫來做一些簡單的事情。所以第一件事照例FIND方法在pymongo和VERSION中不存在?

import pymongo 
connection = pymongo.Connection(host = 'mongodb://username:[email protected]: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

-1沒有想到。您在連接對象上調用find()而不是集合。爲什麼連接實現find()? find()是集合的功能。請RTFM –

+0

你是該死的!我正在查詢連接!隨時刪除問題! – user702846

回答

1

爲什麼要

connection.find({}) 

工作?

您正在猜測API方法而沒有閱讀關於MongoDB和PyMongo的基礎知識。

find()顯然是一個集合的方法,而不是連接的方法。

row = connection.your_collection.find() 

是你什麼。

請在修改之前閱讀文檔並猜測如何使用API​​。

PyMongo文檔中充滿了示例。

+1

我想把-1放在你的傲慢。 SO是人們提問並接受迴應的地方。如果你不喜歡這個問題,你很容易迴避。作爲一個方面說明:你可以很容易地RTF Netiquette。 –

相關問題