Note that there are some explanatory texts on larger screens.

plurals
  1. POQuerying with mongoengine and django
    primarykey
    data
    text
    <p>I have a database "tumblelog" (using mongoengine) in which I added some data in the "user" collection with a "User" model:</p> <blockquote> <p>db.user.find()</p> </blockquote> <pre><code>... { "_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" } </code></pre> <p>When I try <code>User.objects</code> in a django shell, I get the following error:</p> <pre><code>Traceback (most recent call last): File "&lt;console&gt;", line 1, in &lt;module&gt; 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 </code></pre> <p>Same thing when I try</p> <pre><code>for user in User.objects: print user.first_name </code></pre> <p>---- Edit ----</p> <p>I tried this</p> <pre><code>&gt;&gt;&gt; users = User.objects &gt;&gt;&gt; users.count() 7 &gt;&gt;&gt; users.first() ... TypeError: __init__() keywords must be strings </code></pre> <p>---- Edit 2 ----</p> <p>I installed my project this way :</p> <pre><code>&gt; virtualenv Test &gt; source Test/bin/activate &gt; pip install Django &gt; pip install mongoengine &gt; cd Test/ &gt; django-admin.py startproject db </code></pre> <p>Then I added the lines </p> <pre><code>from mongoengine import * connect('tumblelog') </code></pre> <p>in settings.py then I created this simple model</p> <pre><code>from mongoengine import * class User(Document): email = StringField(required=True) name = StringField(max_length=50) </code></pre> <p>then I run the server</p> <pre><code>&gt; python manage.py runserver </code></pre> <p>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: <strong>init</strong>() keywords must be strings !</p> <p>-----Switching to django-mongodb engine----</p> <p>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.</p> <p>What am I doing wrong ? Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload