Mongodb Motor MongoDB 的 Python 驱动开源项目

我要开发同款
匿名用户2014年04月18日
42阅读
开发技术Python
所属分类数据库相关、数据库驱动程序
授权协议Apache

作品详情

Motor为Tornado提供了一个基于回调和Future机制的非堵塞的MongoDB驱动程序。Motor封装了PyMongo

安装:$pipinstallmotor

示例代码:

from tornado import genclass NewMessageHandler(tornado.web.RequestHandler):    @tornado.web.asynchronous    @gen.coroutine    def post(self):        """Insert a message."""        msg = self.get_argument('msg')        db = self.settings['db']        # insert() returns a Future. Yield the Future to get the result.        result = yield db.messages.insert({'msg': msg})        # Success        self.redirect('/')class MessagesHandler(tornado.web.RequestHandler):    @tornado.web.asynchronous    @gen.coroutine    def get(self):        """Display all messages."""        self.write('<a href="/compose">Compose a message</a><br>')        self.write('<ul>')        db = self.settings['db']        cursor = db.messages.find().sort([('_id', -1)])        while (yield cursor.fetch_next):            message = cursor.next_object()            self.write('<li>%s</li>' % message['msg'])        # Iteration complete        self.write('</ul>')        self.finish()

MotorAPI

MotorClient–ConnectiontoMongoDB

MotorReplicaSetClient–ConnectiontoMongoDBreplicaset

MotorDatabase

MotorCollection

MotorCursor

MotorGridFSClasses

motor.web

查看全文
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论