2012-09-13 4 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({}) 

사용할 수 있습니까?

MongoDB 및 PyMongo에 대한 기본 사항을 읽지 않고 API 메소드를 추측하고 있습니다.

find()는 분명히 연결이 아닌 컬렉션의 메서드입니다.

row = connection.your_collection.find() 

무엇입니까?

API를 사용하는 방법을 고민하고 추측하기 전에 문서를 읽으십시오.

PyMongo 설명서에는 많은 예제가 있습니다.

+1

나는 너의 오만함에 -1을 넣고 싶다. 그래서 사람들은 질문을하고 응답을받는 곳입니다. 질문이 마음에 들지 않으면 쉽게 회피 할 수 있습니다. 참고로, RTF 네티켓을 쉽게 만들 수 있습니다. –

관련 문제