[Answered ]-Django + MongoDB using mongodb-engine gives multipleobjectreturned

1đź‘Ť

By default, MongoDB creates a unique index on the _id field. However, it looks like you are using the session_key field, which is not unique by default, which may explain how you’re getting two entries.

Take a look at the indexes that are in use: ./mongo localhost:8000/admin --eval "db.system.indexes.find()" and see if this isn’t just an index problem. Information about creating unique indexes is here.

You may also want to take a look at the code that creates the django_session documents. They may be doing something “not quite right” that’s causing the error.

👤Gates VP

1đź‘Ť

I contacted the author in charge of django-mongodb-engine who had missed out adding django.contrib libraries( Admin library of django belongs in it.) to the test. He added the fix by which now you can access admin without getting the mulipleobjectreturned error.

this is the commit that fixes the issue (https://github.com/django-mongodb-engine/mongodb-engine/issues/53) : https://github.com/django-mongodb-engine/mongodb-engine/commit/a0ab9c3f7c378828c2800b8f62f67c8e21255835

Hope this helps someone else.

👤web_ninja

Leave a comment