0

I am using Django(Django-nonrel) and have models.py that contains all my tables. I would like to create index on some of the tables but I am not able to find documentation that explains how to create indices. I would expect that I can declare the index in models.py and execution of syncdb would create it on the database.

Any help is much appreciated!

Thanks!

4
  • 1
    Firstly, if you want to use NoSQL with Python, use flask, because that has an integration with mongodb called mongoengine, which is awesome. Django is not meant for NoSQL, so please stop using it for that. On top of that, django-nonrel is stuck on version 1.3, a lot of the new libraries simply won't work with it. Commented Sep 11, 2013 at 17:59
  • @GamesBrainiac Thanks for the advice! We are also aware that we are stuck with 1.3, and will evaluate shifting. But for now, is there a way to make some queries faster by adding index? Commented Sep 11, 2013 at 18:22
  • 1
    I know how to do this in mongoengine, but not in django-nonrel. As for shifting, mongoengine will have a django compatible library soon. So, hold on to your hats. Commented Sep 11, 2013 at 18:24
  • 1
    You don't need to predeclare indexes, see this question: stackoverflow.com/questions/11333938/… Commented Sep 11, 2013 at 20:21

1 Answer 1

3

Django-nonrel doesn't interact with mongodb on its own; you need the mongodb python driver (pymongo) and/or an object-document mapper (ODM) such as mongoengine or django-mongodb-engine to interact with the database. It's the job of the ODM and driver to create the indexes, and it depends on what you're using to interact with mongodb as far as what syntax you need to use to create indexes.

You should see the relevant documentation for creating indexes in pymongo, django-mongodb-engine, or mongoengine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.