我有一個put和get函數,它插入到MongoDB的:如何在MongoDB中存儲鎖定對象?
def put(self,key,value):
key = self.path+"&&"+key
value1 = Binary(pickle.dumps(value))
entry = {"keyname":key,"info":value1}
self.filenode.update({"keyname":key}, { "$set" : entry }, upsert=True)
def get(self,key):
key1 = key
key = self.path+"&&"+key
res = self.filenode.find_one({"keyname":key})
if "info" in res:
x = res["info"]
res1 = pickle.loads(x)
return res1
else:
return None
這工作如果放值是簡單的類型,如字符串,快譯通等,但如果值是一個對象時,它是不能夠鹹菜在put函數中。我得到的錯誤是:
raise TypeError, "can't pickle %s objects" % base.__name__
類型錯誤:無法鹹菜鎖定對象