Forums

Django & MongoDB

I know this forum thread covers this question somewhat, but would you guys be able to give me a brief step by step guide to using MongoDB on Mongo Lab on PA? I'm a beginner but have created sites using SQL databases in Django before.

Currently my settings are:

DATABASES = {
    'default': {
        'ENGINE': '',
        #'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    } }

MongoClient('mongodb://<username>:<password>@ds063641-a0.mongolab.com:63641,ds063641-a1.mongolab.com:63641/<database>?replicaSet=rs-ds063641')

Is that all, then you just start writing in the nonrel fashion? Or do I need any other installations other than PyMongo, like Django Nonrel? And how do I interact with the database in bash console.

Thanks a lot for your help.

Connecting to MongoLab from your paid PythonAnywhere account via Python is pretty simple, as you've probably worked out from the forum thread you linked to. We don't have the mongo shell command installed (though we probably should, I've added a ticket) but anything you can do with that you can also do by using the MongoClient package from a Python shell.

Connecting Django to MongoDB is a different matter; you'll need to use a different Django DB engine, as you suspected. I don't know which is best, but MongoEngine looks pretty good. I think you need to change the design of your models, though -- Django's default setup is very much designed for relational databases.

Has anyone else out there done much with Django and MongoDB?

Some extra information -- here's a help page about MongoDB on PythonAnywhere that hopefully will be useful for anyone with questions about the connection-related side of this in the future (but not the Django stuff).