web_ninja
web_ninja

Reputation: 2401

Django + MongoDB using mongodb-engine gives multipleobjectreturned

when i access localhost:8000/admin gives me the error 'MultipleObjectsReturned at /admin/ get() returned more than one Session -- it returned 2! Lookup parameters were {'session_key': 'ee5a8be487352e42a89f962ee4ab22a6', 'expire_date__gt': datetime.datetime(2011, 7, 8, 5, 38, 36, 645053)}'

if access the mongodb and delete one of the rows in the collection django_session it works, but after awhile gives me the same error because it was created another document in the collection django_session

update : even in the browser i deleted the cookie that stored the session id then i was able to run the page smoothly. then when i refresh or click on the link i get the multiple object returned error.

is this a problem with the mongodb-engine for django that tries to add session ids for every page refresh.

Upvotes: 1

Views: 719

Answers (2)

web_ninja
web_ninja

Reputation: 2401

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.

Upvotes: 1

Gates VP
Gates VP

Reputation: 45307

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.

Upvotes: 1

Related Questions