python mongodb light工具包

MongoLite的Python项目详细描述


蒙古人是同一作者的一个分支。它的目标是通过剥离许多特性并用最佳实践替换它们来回归简单。

蒙古人的目标是尽可能地坚持使用pymongo api。 蒙古人总是选择速度超过合成糖,这就是为什么你看不到的原因。 此项目中的验证或点标记功能。

蒙古人是完美的谁想要一个薄薄的一层皮蒙哥,而不关心验证的东西。

蒙古人是美丽的stone

您的数据是干净的

“工具改变,而不是数据”。为了遵循这个“信条”,就像 Mongokit,Mongolite不会将任何信息添加到保存到 数据库。所以如果你需要用其他的Mongo工具或者其他语言的ODM, 你的数据不会被蒙古人的东西污染。

功能

  • schema less feature
  • inheritance and polymorphisme support
  • skeleton generation (your object is automaticaly filled by the correct fields)
  • nested and complex schema declaration
  • default values features
  • random query support (which returns a random document from the database)
  • json helpers
  • GridFS support

一个简单的例子

文档声明如下:

>>> from mongolite import *
>>> import datetime

>>> connection = Connection()

>>> @connection.register
... class BlogPost(Document):
...     __database__ = 'test'
...     __collection__ = 'example'
...     skeleton = {
...             'title':unicode,
...             'body':unicode,
...             'author':unicode,
...             'date_creation':datetime.datetime,
...             'rank':int
...     }
...     optional = {
...             'tags': [unicode],
...     }
...     default_values = {'rank':0, 'date_creation':datetime.datetime.utcnow}
...

>>> blogpost = con.BlogPost() # this use the db "test" from `__database__` and the collection "example" from `__collection__`
>>> blogpost # the skeleton is automatically generated (based on the skeleton attribute)
{'body': None, 'title': None, 'date_creation': datetime.datetime(...), 'rank': 0, 'author': None}
>>> blogpost['title'] = u'my title'
>>> blogpost['body'] = u'a body'
>>> blogpost['author'] = u'me'
>>> blogpost['tags'] = ['about me', 'first post']
>>> blogpost
{'body': u'a body', 'title': u'my title', 'date_creation': datetime.datetime(...), 'rank': 0, 'author': u'me', 'tags': [u'about me', u'first post']}
>>> blogpost.save()

注意,虽然文档中应该有skeleton中的字段,但默认情况下不会生成optional属性中的字段。它旨在仅用于文档…

要访问这些字段,请使用以下约定:

用于骨架中的字段

>>> title = blogpost['title']

用于可选字段

>>> tags = blogpost.get('tags', [])

蒙古人写在皮蒙哥的上面。所有pymongo的api都是可访问的,结果都被包装到文档对象中:

>>> blogpost = con.BlogPost.find_one() # this is a blogpost object

但是,如果需要更多性能,可以直接使用pymongo层:

>>> blogpost = con.test.example.find_one() # this is a dict

建议和补丁非常受欢迎。如果你在文件中发现错误 (英语不是我的主要语言)随时与我联系。你可以找到我(南望) 在twitter上。

最近的更改日志

v1.5

  • support pymongo 2.4

v1.4

  • support pymongo 2.3
  • added fix for unconditional access to __wrap on cursors
  • add __getitem__ suport on Cursor

v1.3

  • change pymongo.objectid -> bson.objectid as this alias was deleted in pymongo 2.2
  • add exception in case of bad behavior with inherited queries

v1.2

  • fix generate_indexes() and slightly api change

v1.1

  • add inherited queries support
  • add serialize support
  • fix pymongo’s version

v1.0

  • fork from MongoKit, strip all unwanted features

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java日期格式的月和日的固定长度?   无法将java ArrayList<String>转换为字符串。   java当我使用log4j 1.2.15时,编译时出现错误;当更改为1.2.16时,一切正常   java如何使用ArgumentMatchers将任何队列告知Mockito?   如何解决“java”。Java电子邮件API中的lang.ExceptionInInitializerError   java是实例化对象名并设置其值的通用方法   java在多线程环境中,如果一个线程崩溃,如何关闭JVM?   java WebDriverManager在selenium中获取不正确版本的驱动程序   如果JAVA中后减量的优先级高于前增量,那么为什么下面的代码输出为22.0而不是20.0。?   在hibernate中找不到java属性   当我用java运行调度程序时,什么都没有发生   jackson如何在java中从数据库中检索json对象   java安卓:如何在自定义适配器中设置侦听器并获取imagebutton单击的位置   java MySQLIntegrityConstraintViolationException:列“问题id”不能为空错误   JavaSpring自定义注销过滤器在注销前执行一些操作?   java如何返回常量集合   java使用subselect进行一对多分页   java二进制搜索基础。陷入无限循环