Save 37% off PRO during our Black Friday Sale! »

Mnj — the MongoDB library which does it right

Mnj — the MongoDB library which does it right

There are a lot of MongoDB libraries for Python. Some of them could be very helpful. But when it comes to use PyMongo we are stuck with dicts and strings. Mnj (MongoEnergy) is here to fix it.

200442040b9d038626d92d408f499642?s=128

Serge Matveenko

June 17, 2016
Tweet

Transcript

  1. Serge Matveenko DataArt github.com/lig Mnj — the MongoDB library which

    does it right
  2. MongoDB smells bad? But it’s profitable and delicious

  3. 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
  4. 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`
  5. MongoEngine MongoEngine PyMongo a lot of magic

  6. MongoEngine vs Mnj MongoEngine PyMongo a lot of magic Mnj

    ODM Level PyMongo Mnj DSL Level Mnj Feature Level
  7. Comparison PyMongo MongoEngine Mnj Objects Mapping - Validation - Usability

    MongoDB like PyMongo Compatibility Defending errors
  8. PyMongo Example books = col.find({ 'author': {'$regex': 'Gibson', '$options': 'i'},

    'year': {'$gte': 2003}, }) for book in books: print(book['title'])
  9. Comparison PyMongo MongoEngine Mnj Objects Mapping - Validation - Usability

    - MongoDB like + PyMongo Compatibility + :) Defending errors -
  10. 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)
  11. Comparison PyMongo MongoEngine Mnj Objects Mapping - + Validation -

    + Usability - ± MongoDB like + - PyMongo Compatibility + :) - Defending errors - ±
  12. Mnj Example books = col.find(q( author=regex_('Gibson', re.IGNORECASE), year=gte_(2003) )) for

    book in books: print(book['title'])
  13. 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'])
  14. 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'])
  15. Comparison PyMongo MongoEngine Mnj Objects Mapping - + + unstable

    Validation - + + planned Usability - ± + MongoDB like + - + PyMongo Compatibility + :) - + Defending errors - ± + improving
  16. 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)
  17. 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
  18. Thank you! github.com/lig/mnj