用于访问基于tornado ioloop的mongodb的异步库。
asyncmongo的Python项目详细描述
AsyncMongo是一个访问Mongo的异步库,它建立在Tornado IOLoop上。[构建状态](https://travis-ci.org/bitly/asyncMongo.png?branch=master)(https://travis ci.org/bitly/asyncMongo)
安装
----
安装:`pip install asyncMongo`
用法
-
asyncMongo语法力求与[pymongo]类似(http://api.mongodb.org/python/current/api/pymongo/collection.html)。
import asyncMongo
importtornado.web
类处理程序(tornado.web.requesthandler):
@property
def db(self):
如果不是hasattr(self,“\u db”):
self.\u db=asyncMongo.client(pool_id='mydb',host='127.0.0.1',port=27017,maxcached=10,maxconnections=50,dbname='test')
返回self.\u db
@tornado.web.asynchronous
def get(self):
self.db.users.find({'username':self.current嫒user},limit=1,callback=self.\u on嫒response)
或
conn=self.db.connection(collectionname=“…”,dbname=“…”
conn.find(…,callback=self.\u on\u response)
def\u on\u response(self,response,error):
如果错误:
引发tornado.web.httperror(500)
self.render('template',full_name=response['full_name'])
删除集合
*成批而不是一次全部检索结果
(AsyncMongo的性质意味着无论检索多少结果,都不会阻塞任何调用)
*可裁剪的游标15
*[PyMongo](http://github.com/mongodb/mongo-python-driver)1.9+版,适用于bson库
*[tornado](http://github.com/facebook/tornado)
问题
----
请通过[github问题](https://github.com/bitly/asyncMongo/issues)报告任何问题。
安装
----
安装:`pip install asyncMongo`
用法
-
asyncMongo语法力求与[pymongo]类似(http://api.mongodb.org/python/current/api/pymongo/collection.html)。
import asyncMongo
importtornado.web
类处理程序(tornado.web.requesthandler):
@property
def db(self):
如果不是hasattr(self,“\u db”):
self.\u db=asyncMongo.client(pool_id='mydb',host='127.0.0.1',port=27017,maxcached=10,maxconnections=50,dbname='test')
返回self.\u db
@tornado.web.asynchronous
def get(self):
self.db.users.find({'username':self.current嫒user},limit=1,callback=self.\u on嫒response)
或
conn=self.db.connection(collectionname=“…”,dbname=“…”
conn.find(…,callback=self.\u on\u response)
def\u on\u response(self,response,error):
如果错误:
引发tornado.web.httperror(500)
self.render('template',full_name=response['full_name'])
删除集合
*成批而不是一次全部检索结果
(AsyncMongo的性质意味着无论检索多少结果,都不会阻塞任何调用)
*可裁剪的游标15
*[PyMongo](http://github.com/mongodb/mongo-python-driver)1.9+版,适用于bson库
*[tornado](http://github.com/facebook/tornado)
问题
----
请通过[github问题](https://github.com/bitly/asyncMongo/issues)报告任何问题。