Skip to main content

Sytax sugar for PyMongo and MongoDB <>

Project description

Info:See the mongo site for more information. See github for the latest source.
Author: Alexander Artemenko <>


The PyMongoBongo distribution contains wrappers to add some syntax sugar to PyMongo for easier interaction with the Mongo database using “python way”.



  • Fixed __len__ method, broken by changes in pymongo 1.1.1. Now mongobongo depends on pymongo >= 1.1.1.


  • Fixed ordering in case, when ‘find_one’ is used.
  • Fixed default cursor ordering, now it is applied in the constructor.


  • Added automatic DBRef usage, when one document contains another. Here is an example:

    >>> author = Author(name = 'Alexander')
    >>> article =  Article(title = 'Life is miracle', author = author)
    >>> Author.objects.count()
    >>> article = Article.objects.find_one()
    >>> Author.objects.count()


  • Basic support for documents with attributes.


If you have setuptools installed you should be able to do easy_install pymongo-bongo to install PyMongoBongo. Otherwise you can download the project source and do python install to install.


The PyMongoBongo depends on PyMongo >= 1.1.1

Additional dependencies are:

  • (to generate documentation) epydoc
  • (to auto-discover tests) nose


Here’s a basic example:

>>> from pymongo.connection import Connection
>>> from mongobongo import Document
>>> class Article(Document):
...     collection = 'articles'
...     def get_full_title(self):
...         return '%s (%s)' % (self.title, ', '.join(self.tags))
>>> connection = Connection("localhost", 27017)
>>> Article.objects.db = connection.test
>>> article = Article(author = 'Alex', title = 'Pink Pony\'s Life', tags = ['mongo', 'bongo'])
>>> articles = Article.objects.all()
>>> len(articles)
>>> article = Article(author = 'Alex', title = 'Long Long Python', tags = ['python', 'devel'], subtitle = 'Not such long')
>>> articles = Article.objects.all()
>>> len(articles)
>>> python_articles = Article.objects.find({'tags': 'python'})
>>> len(python_articles)
>>> python_articles[0].title
'Long Long Python'


You will need epydoc installed to generate the documentation. Documentation can be generated by running python doc. Generated documentation can be found in the doc/ directory.


The easiest way to run the tests is to install nose (easy_install nose) and run nosetests or python test in the root of the distribution. Tests are located in the test/ directory.


  • Slava Vishnyakov, for ‘Document.remove’ method.

Wanna be listed here? Go to the GitHub, fork the project and send me patches :)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymongo-bongo-0.1.3.tar.gz (12.1 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page