0

[SOLVED] After successfully completing the django tutorial, I have tried to use mongoDB as a database, with Django MongoDB Engine. This is the database configuration in settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django_mongodb_engine', 
        'NAME': 'test',                               
        'HOST': 'localhost',               
        'PORT': 27017,                   
#       'OPTIONS' : {
#           'slave_okay' : True,
#       }
    }
}

And this is the error message I get, after running python manage.py syncdb :

raise AutoReconnect("could not find master/primary")
pymongo.errors.AutoReconnect: could not find master/primary

I got this error, even after shutting down the mongoDB server, so I figured out that this needed to be a connection issue. I posted an answer on how I solved this.


Using Ubuntu 12.04 LTS x64, Python 2.7, django 1.4.2, mongoDB x86_64 2.2.1 (clean new install)

Nicolas Cortot
  • 6,591
  • 34
  • 44
DrKaoliN
  • 1,346
  • 4
  • 25
  • 39
  • did you set up a replica set? If you are only connecting to a single server 'slave_okay' option doesn't make any sense... – Asya Kamsky Nov 26 '12 at 20:07
  • As I mentioned, I don't use a replica set. Initially, I was not using the `OPTIONS` entry, but the error was exactly the same. I added it because I thought that it might help. With or without it, I get the same error. – DrKaoliN Nov 26 '12 at 21:24
  • invalid ns just means there is no users collection in the database you are connected to. Your database is not corrupt - it apparently doesn't contain appropriate collections/schema that's expected. – Asya Kamsky Nov 27 '12 at 17:43
  • how do you connect to your mongoDB with mongo shell? – Asya Kamsky Nov 27 '12 at 17:46
  • I can connect through the `mongo` shell, yes, but not through the django app. But, I actually just solved the django `syncdb` problem. – DrKaoliN Nov 27 '12 at 17:50
  • maybe you can post what you had to do to solve it, as an answer (in case others might have the same problem) – Asya Kamsky Nov 27 '12 at 17:56
  • Oh, I thought I couldn't answer with only 6 rep points. – DrKaoliN Nov 27 '12 at 18:04
  • I guess I should delete the second question from this post, an create a new one. – DrKaoliN Nov 27 '12 at 18:11
  • I posted the second question here: http://stackoverflow.com/questions/13590638/mongodb-2-2-1-database-not-valid – DrKaoliN Nov 27 '12 at 18:26
  • @AsyaKamsky You are so right about the invalid ns! Thanks a lot! – DrKaoliN Nov 27 '12 at 19:30

2 Answers2

3

The way I solved this is so simple that I am almost ashamed at myself for asking the question in the first place, but I hope it will be useful:

I simply upgraded the Django MongoDB Engine by typing into the terminal:

sudo pip install git+https://github.com/django-nonrel/mongodb-engine --upgrade

And that's it.

Nicolas Cortot
  • 6,591
  • 34
  • 44
DrKaoliN
  • 1,346
  • 4
  • 25
  • 39
0

Can you try running ...

db.repairDatabase()

... from the mongo terminal?

juan
  • 80,295
  • 52
  • 162
  • 195
  • That, and starting `mongod --repair`, didn't help. – DrKaoliN Nov 27 '12 at 14:05
  • `db.repairDatabase()` reurns `{ "ok" : 1 }`. But after that, `db.users.validate()` returns the same `{ "errmsg" : "ns not found", "ok" : 0, "valid" : false }`, and I still cannot connect to the database with django. – DrKaoliN Nov 27 '12 at 14:07