2013-03-18 2 views
0
@connection.register 
class User(Document): 

    __database__ = 'foo' 
    __collection__ = 'bar' 

    structure = { 
    '_id' : ObjectId, 
    'Email' : basestring,  
} 


col = connection['uplace']['user'] 
user = col.find()[2] 
user2 = User(user) 
user2['Email'] = '[email protected]' 
#connection.register([user]) 
#user['Wall'][1]['Reply'][0]['Message'] = 'test new message' 
#print user 
user2.save() 

그러나 이것을 실행할 때 개체를 받고 내 UserDocument의 인스턴스입니다. 그러나이 예외가 발생합니다 :mongokit을 사용하여 find()를 수행 한 후 객체를 업데이트하는 방법은 무엇입니까?

server_version = tuple(self.connection.server_info()['version'].split(".")) 
    File "/Library/Python/2.7/site-packages/mongokit/document.py", line 628, in __getattribute__ 
    raise ConnectionError('No collection found') 
mongokit.mongo_exceptions.ConnectionError: No collection found 

답변

0

올바른 방법은 다음과 같습니다

user2 = col.User(user) 
user2.pop('_id') # you should remove the _id or saving user2 will replace user 
user2["Email"] = "[email protected]" 
user2.save() 
관련 문제