设为首页收藏本站

LUPA开源社区

 找回密码
 注册
文章 帖子 博客
LUPA开源社区 首页 业界资讯 软件追踪 查看内容

Motor 0.3.2发布,MongoDB的Python驱动

2014-7-17 17:12| 发布者: joejoe0332| 查看: 1594| 评论: 0|原作者: oschina|来自: oschina

摘要:   Motor 0.3.2 发布,此版本兼容 MongoDB 2.2,2.4 和 2.6,最低要求 PyMongo 2.7.1。  此版本修复了在 "copy_database" 方法的 socket 泄漏,重写了"Let Us Now Praise ResourceWarnings"里面的问题和 bug。  ...

  Motor 0.3.2 发布,此版本兼容 MongoDB 2.2,2.4 和 2.6,最低要求 PyMongo 2.7.1。


  此版本修复了在 "copy_database" 方法的 socket 泄漏,重写了 "Let Us Now Praise ResourceWarnings" 里面的问题和 bug。


  获得最新版本:pip install --upgrade motor。更多内容请看这里


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


  安装:$ pip install motor


示例代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from tornado import gen
  
class 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()

Motor API



酷毙

雷人

鲜花

鸡蛋

漂亮
  • 快毕业了,没工作经验,
    找份工作好难啊?
    赶紧去人才芯片公司磨练吧!!

最新评论

关于LUPA|人才芯片工程|人才招聘|LUPA认证|LUPA教育|LUPA开源社区 ( 浙B2-20090187 浙公网安备 33010602006705号   

返回顶部