Motor 0.3.2 發佈,MongoDB 的 Python 驅動

來源:互聯網
上載者:User

Motor 0.3.2 發佈,此版本相容 HTTP://www.aliyun.com/zixun/aggregation/13461.html">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

示例代碼:

?123456789101112131415161718192021222324252627282930313233from 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})      & nbsp;     # 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)])       & nbsp; while (yield cursor.fetch_next):             message = cursor.next_ object()             self.write('<li>%s</li>' % message['msg']) & nbsp;          # Iteration complete         self.write('</ul>') & nbsp;       self.finish()

Motor API

MotorClient – Connection to MongoDB

MotorReplicaSetClient – Connection to MongoDB replica set

MotorDatabase

MotorCollection

MotorCursor

Motor GridFS Classes

motor.web

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.