I have a database “tumblelog” (using mongoengine) in which I added some data in the “user” collection with a “User” model:
db.user.find()
...
{ "_id" : ObjectId("4fb0c9494ca88402dd000000"), "_types" : [ "User" ], "first_name" : "John", "last_name" : "Doe", "_cls" : "User", "email" : "jdoe@example.com" }
{ "_id" : ObjectId("4fb0cb9d4ca88402ec000000"), "_types" : [ "User" ], "first_name" : "Joe30", "last_name" : "Foe", "_cls" : "User", "email" : "hu@huu.com" }
When I try User.objects in a django shell, I get the following error:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File ".../mongoengine/queryset.py", line 1127, in __getitem__
return self._document._from_son(self._cursor[key])
File ".../mongoengine/base.py", line 1018, in _from_son
obj = cls(**data)
TypeError: __init__() keywords must be strings
Same thing when I try
for user in User.objects:
print user.first_name
—- Edit —-
I tried this
>>> users = User.objects
>>> users.count()
7
>>> users.first()
...
TypeError: __init__() keywords must be strings
—- Edit 2 —-
I installed my project this way :
> virtualenv Test
> source Test/bin/activate
> pip install Django
> pip install mongoengine
> cd Test/
> django-admin.py startproject db
Then I added the lines
from mongoengine import *
connect('tumblelog')
in settings.py
then I created this simple model
from mongoengine import *
class User(Document):
email = StringField(required=True)
name = StringField(max_length=50)
then I run the server
> python manage.py runserver
And in the shell (python manage.py shell) I can save data if I import my model class but I can’t read it, I always have the same TypeError: init() keywords must be strings !
—–Switching to django-mongodb engine—-
I didn’t find any solution so I will use django-mongodb-engine. I did not find any comparison, but I tried both and it’s very similar.
I just regret django-mongodb-engine doesn’t handle inheritance principle.
What am I doing wrong ?
Thanks in advance!
we had the exact same issue using mongoengine 0.6.9. I am not suggesting this as an ideal solution but downgrading to 0.6.5 resolved this issue for us.