To install pymongo2django:
copy pymongo2django directory to your Python path
The follow software requirement to install pymongo2django app:
* Python 2.7.x * Pymongo Driver (latest version preferred) * MongoDB Server (http://www.mongodb.org) only if database is installed locally on your machine otherwise you can access database from the cloud through MongoDB servers online (http://www.mongolab.com/)
To use pymongo2django with your Python projects/code, just import this Python library into your code:
***IMPORTANT NOTES:: pymongo2django api is similar to Django/SQLAlchemy. Update the pymongo2django/settings.py file found inside the pymongo2django directory. Update these variables in the pymongo2django/settings.py file to use database.Ensure also that the MongoDB server is running or otherwise use a MongoDB server from an online vender/host.
For instance, to create a MongoDB instance to a collection via Document model class:
>>> import pymongo2django >>> from book.models import Author >>> author = Author() >>> author.setName(author.name)
To find an item in a collection:
>>> import pymongo2django >>> from book.models import Author >>> author = Author() >>> author.setName(author.name) >>> for row in author.objects.find(): >>> print row
For instance, to create MongoDB instance (using a Replica Set Configuration) to access a collection via DocumentSet model class:
>>> import pymongo2django >>> from book.models import AuthorSet >>> authorset = AuthorSet() >>> authorset.setName(authorset.name)
To find an item in a collection:
>>> import pymongo2django >>> from book.models import AuthorSet >>> authorset = AuthorSet() >>> authorset.setName(authorset.name) >>> for row in authorset.objects.find(): >>> print row
books/models.py:
from pymongo2django import DocumentSet class AuthorSet(DocumentSet): name='products'
books/models.py:
from pymongo2django import Document class Author(Document): name='products' ***IMPORTANT NOTES:: pymongo2django\settings.py cannot use multiple configuration settings. So once a Document model object or DocumentSet object is created the settings for the database name is locked into either object type created. For instance a Document Model object using a database name 'Work' and you want to change that database name to something else the current Document model object is using. You would have to change the pymongo2django\settings.py file to reflect the changes for the new database name and then re-instantiate the object when done. The same applies when using the DocumentSet only where the current database setting being used is different from the new database settings.