I have a tumblelog database (using mongoengine) in which I added some data to the user collection using the 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.objectsin the 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 set up 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 start 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 types: init () should be strings!
----- django-mongodb ----
, django-mongodb-engine. , , .
, django-mongodb .
?
!