(MongoDB+Tornado)是一个异步驱动程序和工具包,用于在Tornado应用程序中使用MongoDB
mongotor的Python项目详细描述
#什么是Mongotor?
(mongodb+tornado)是一个异步工具包,用于在"tornado"应用程序中使用"mongodb"。Mongotor有一个python+tornado的纯实现,它只依赖于tornado和bson(由pymongo提供)
[![构建状态](https://travis-ci.org/marcelnicolay/mongotor.svg?branch=master)(https://travis ci.org/marcelnicolay/mongotor)
ing数据库命令(``count``,``sum`,``mapreduce``等…)
*``orm``喜欢映射文档和字段
*``signals``用于预保存、后保存、预删除、后删除、预更新和后更新
*100%的代码覆盖率(通过测试
/>*sharding
*authentication
*副本集中最接近的首选项
*gridfs
*所有python版本(2.5、2.6、2.7、3.2和pypypy),现在只测试python 2.7
<为什么不去皮蒙戈呢?
[pymongo](http://api.mongodb.org/python/current/)是在python中使用mongodb的推荐方法,但它不是异步的,也不在de tornado的ioloop中运行。如果你使用Pymongo,你不会利用龙卷风的优势。
[马达](http://emptysquare.net/motor/)包装pymongo并使其与greenlet异步。是一个伟大的项目,但它使用绿色。如果你能用绿色的,为什么不用绿色的替代龙卷风呢?pymongo已经在gevent中工作了,您不需要考虑使用回调编写所有代码。我的观点是,如果您使用的是一个非常强大的无阻塞web服务器,带有纯python代码,那么您可能需要使用一个纯tornado驱动程序来访问mongo,显然,因为这个模块完全支持像pymongo这样的mongodb功能。
[asyncMongo](https://github.com/bitly/asyncMongo)是一个使用tornado.ioloop访问MongoDB的异步库,但是没有实现副本集和其他MongoDB功能。
此外,这个项目走得不是很好,或者更好,也不是很快。存在许多问题和拉取请求,但这些问题和请求并没有被发现。
##安装
``` bash
pip install mongotor
```
初始化(self):
self.db=database.init('localhost:27017','mongotor嫒test')
@tornado.web.asynchronous
@gen.engine
def get(self):
user={''u id':objectid(),'name':'user name'}
yield gen.task(self.db.user.insert,user)
yield gen.task(self.db.user.update,user['''u id',{"$set":{'name':'new user name'})
user\u found=yield gen.task(self.db.user.find\u one,user[''u id'])
assert user\u found['name'='new user name'
yield gen task(self.db.user.remove,user[''u id'})'])
```
``python
``import tornado.web
from tornado import gen
from mongotor.database import database
from mongotor.node import readpreference
from bson import objectid
import time
class handler(tornado.web.requesthandler):
def initialize(self):
配置副本集
self.db=db=数据库.init(["localhost:27027","localhost:27028"],dbname="mongotor庠test",
read庠preference=readpreference.secondary庠preference)
@tornado.web.asynchronous
@gen.engine
def get(self):
用户={"u id":objectid()}
ari
yield gen.task(self.db.user.insert,user)
r/>使用mongotor.orm导入集合中的orm
`` python
,mongotor.database导入数据库中的field
from datetime import datetime
import torado.web
from torado import gen
执行操作
database.init(['localhost:27017','localhost:27018','mongotor_test')
类用户(collection.collection):
=field.datetimefield()
类处理程序(tornado.web.requesthandler):
@tornado.web.asynchronous
@gen.engine
def get(self):
user=user()
user.name="user name"
user.active=true
user.created=datetime.now()
生成生成任务(user.save)
new_user=user()
new_user.name="new user name"
new_user.user.active=true
new_user.created=datetime.now()
users_actives=yield gen.task(user.objects.find,{'active':true})
users_actives[0].active=false
yield gen.task(用户活跃[0].save)
一个新的Virtualenv
>mkvirtualenv mongootor
>安装开发需求
>pip install-r requirements-dev.txt
>启动mongo
>make mongo start
>配置复制集
>make mongo config
>运行测试
>make test
````
>问题
>请代表通过[GitHub问题](https://github.com/marcelnicolay/mongotor/issues)排序任何问题
(mongodb+tornado)是一个异步工具包,用于在"tornado"应用程序中使用"mongodb"。Mongotor有一个python+tornado的纯实现,它只依赖于tornado和bson(由pymongo提供)
[![构建状态](https://travis-ci.org/marcelnicolay/mongotor.svg?branch=master)(https://travis ci.org/marcelnicolay/mongotor)
ing数据库命令(``count``,``sum`,``mapreduce``等…)
*``orm``喜欢映射文档和字段
*``signals``用于预保存、后保存、预删除、后删除、预更新和后更新
*100%的代码覆盖率(通过测试
/>*sharding
*authentication
*副本集中最接近的首选项
*gridfs
*所有python版本(2.5、2.6、2.7、3.2和pypypy),现在只测试python 2.7
<为什么不去皮蒙戈呢?
[pymongo](http://api.mongodb.org/python/current/)是在python中使用mongodb的推荐方法,但它不是异步的,也不在de tornado的ioloop中运行。如果你使用Pymongo,你不会利用龙卷风的优势。
[马达](http://emptysquare.net/motor/)包装pymongo并使其与greenlet异步。是一个伟大的项目,但它使用绿色。如果你能用绿色的,为什么不用绿色的替代龙卷风呢?pymongo已经在gevent中工作了,您不需要考虑使用回调编写所有代码。我的观点是,如果您使用的是一个非常强大的无阻塞web服务器,带有纯python代码,那么您可能需要使用一个纯tornado驱动程序来访问mongo,显然,因为这个模块完全支持像pymongo这样的mongodb功能。
[asyncMongo](https://github.com/bitly/asyncMongo)是一个使用tornado.ioloop访问MongoDB的异步库,但是没有实现副本集和其他MongoDB功能。
此外,这个项目走得不是很好,或者更好,也不是很快。存在许多问题和拉取请求,但这些问题和请求并没有被发现。
##安装
``` bash
pip install mongotor
```
初始化(self):
self.db=database.init('localhost:27017','mongotor嫒test')
@tornado.web.asynchronous
@gen.engine
def get(self):
user={''u id':objectid(),'name':'user name'}
yield gen.task(self.db.user.insert,user)
yield gen.task(self.db.user.update,user['''u id',{"$set":{'name':'new user name'})
user\u found=yield gen.task(self.db.user.find\u one,user[''u id'])
assert user\u found['name'='new user name'
yield gen task(self.db.user.remove,user[''u id'})'])
```
``python
``import tornado.web
from tornado import gen
from mongotor.database import database
from mongotor.node import readpreference
from bson import objectid
import time
class handler(tornado.web.requesthandler):
def initialize(self):
配置副本集
self.db=db=数据库.init(["localhost:27027","localhost:27028"],dbname="mongotor庠test",
read庠preference=readpreference.secondary庠preference)
@tornado.web.asynchronous
@gen.engine
def get(self):
用户={"u id":objectid()}
ari
yield gen.task(self.db.user.insert,user)
r/>使用mongotor.orm导入集合中的orm
`` python
,mongotor.database导入数据库中的field
from datetime import datetime
import torado.web
from torado import gen
执行操作
database.init(['localhost:27017','localhost:27018','mongotor_test')
类用户(collection.collection):
=field.datetimefield()
类处理程序(tornado.web.requesthandler):
@tornado.web.asynchronous
@gen.engine
def get(self):
user=user()
user.name="user name"
user.active=true
user.created=datetime.now()
生成生成任务(user.save)
new_user=user()
new_user.name="new user name"
new_user.user.active=true
new_user.created=datetime.now()
users_actives=yield gen.task(user.objects.find,{'active':true})
users_actives[0].active=false
yield gen.task(用户活跃[0].save)
一个新的Virtualenv
>mkvirtualenv mongootor
>安装开发需求
>pip install-r requirements-dev.txt
>启动mongo
>make mongo start
>配置复制集
>make mongo config
>运行测试
>make test
````
>问题
>请代表通过[GitHub问题](https://github.com/marcelnicolay/mongotor/issues)排序任何问题