Slide 1

Slide 1 text

Serge Matveenko DataArt github.com/lig Mnj — the MongoDB library which does it right

Slide 2

Slide 2 text

MongoDB smells bad? But it’s profitable and delicious

Slide 3

Slide 3 text

MongoDB state in Python ● PyMongo — main driver ○ Direct MongoDB syntax mapping to dicts. ○ Officially supported ○ Has async derivative “Motor” ● MongoEngine — most popular ODM ○ Class to Collection mapping ○ Django-like syntax ○ Has async derivative “MotorEngine” ● Other ○ TxMongo (Twisted, PyMongo-like) ○ MongoKit (alternative ODM, lack of maintenance, slow, was buggy) ○ Some Django hacks, etc

Slide 4

Slide 4 text

About Mnj ● “Mnj” stands for “Mongo Energy” ● Query DSL for PyMongo-like API ● Helper Library that implements useful features ● Object Document Mapping (ODM) ● Licensed under BSD 2-clause license ● Well coded and tested (PEP-8, 99% coverage) ● `pip install mnj`

Slide 5

Slide 5 text

MongoEngine MongoEngine PyMongo a lot of magic

Slide 6

Slide 6 text

MongoEngine vs Mnj MongoEngine PyMongo a lot of magic Mnj ODM Level PyMongo Mnj DSL Level Mnj Feature Level

Slide 7

Slide 7 text

Comparison PyMongo MongoEngine Mnj Objects Mapping - Validation - Usability MongoDB like PyMongo Compatibility Defending errors

Slide 8

Slide 8 text

PyMongo Example books = col.find({ 'author': {'$regex': 'Gibson', '$options': 'i'}, 'year': {'$gte': 2003}, }) for book in books: print(book['title'])

Slide 9

Slide 9 text

Comparison PyMongo MongoEngine Mnj Objects Mapping - Validation - Usability - MongoDB like + PyMongo Compatibility + :) Defending errors -

Slide 10

Slide 10 text

MongoEngine Example class Book(Document): author = StringField() year = IntField() title = StringField() books = Book.objects(author__icontains='Gibson', year__gte=2003) for book in books: print(book.title)

Slide 11

Slide 11 text

Comparison PyMongo MongoEngine Mnj Objects Mapping - + Validation - + Usability - ± MongoDB like + - PyMongo Compatibility + :) - Defending errors - ±

Slide 12

Slide 12 text

Mnj Example books = col.find(q( author=regex_('Gibson', re.IGNORECASE), year=gte_(2003) )) for book in books: print(book['title'])

Slide 13

Slide 13 text

Mnj mixed with PyMongo Example books = col.find(q( q(author=regex_('Gibson', re.IGNORECASE)), {'year': {'$gte': 2003}} )) for book in books: print(book['title'])

Slide 14

Slide 14 text

Mnj mixed with PyMongo Example books = col.find( q(year=mod_(divisor=1000, remainder=42)) | q(year=mod_(1000, 13)) ) for book in books: print(book['title'], book['author'])

Slide 15

Slide 15 text

Comparison PyMongo MongoEngine Mnj Objects Mapping - + + unstable Validation - + + planned Usability - ± + MongoDB like + - + PyMongo Compatibility + :) - + Defending errors - ± + improving

Slide 16

Slide 16 text

Planned Mnj Features ● Map/Reduce and Aggregation framework support ● Object Document Mapping (different types in the same query) ● Document linking/referencing ● Redundant data in document references ● Large documents (transparently split and merge docs>16MB) ● Bucketing (transparently store series in a single document)

Slide 17

Slide 17 text

How to help ● Provide use cases for improving DSL https://pypi.python.org/pypi/mnj ● Star and fork on Github https://github.com/lig/mnj ● Implement and contribute features https://github.com/lig/mnj/issues ● Join chat and ask questions on Gitter https://gitter.im/lig/mnj

Slide 18

Slide 18 text

Thank you! github.com/lig/mnj