@@ -0,0 +1,1058 @@
+import json%0A%0Afrom . import SessionStorage%0A%0A%0Aclass MongoDBStorage(SessionStorage):%0A    def __init__(self, collection):%0A        import pymongo%0A        assert isinstance(collection,%0A                          pymongo.collection.Collection)%0A        self.collection = collection%0A        collection.create_index(%22wechat_id%22)%0A%0A    def _get_document(self, id):%0A        return self.collection.find_one(%7B%22wechat_id%22: id%7D)%0A%0A    def get(self, id):%0A        document = self._get_document(id)%0A        if document:%0A            return json.loads(document%5B%22session%22%5D)%0A        return %7B%7D%0A%0A    def set(self, id, value):%0A        document = self._get_document(id)%0A        session = json.dumps(value)%0A        if document:%0A            document%5B%22session%22%5D = session%0A            self.collection.save(document)%0A        else:%0A            self.collection.insert(%7B%0A                %22wechat_id%22: id,%0A                %22session%22: session%0A            %7D)%0A%0A    def delete(self, id):%0A        document = self._get_document(id)%0A        if document:%0A            self.collection.remove(document%5B%22_id%22%5D)%0A

add MongoDBStorage #14