1

我正在使用Mongoengine。当我做一个:

>>> Grant.objects().first().client_id

结果符合预期。

ObjectId('526fd0da82353536892f22ae')

client_id但是,当我基于

>>> Grant.objects(client_id="526fd0da82353536892f22ae").first()

我得到一个 InvalidQueryError:

InvalidQueryError: Cannot resolve field "client_id" 这是我的 Grant 模型的样子:

class Grant(db.Document):
    #user_id = db.StringField()
    user = db.ReferenceField(User)
    client_id = db.StringField()
    client = db.ReferenceField(Client)
    code = db.StringField()
    redirect_uri = db.StringField()
    expires = db.DateTimeField()
    scopes = db.ListField()

    #for soft-deleting the grant
    is_deleted = db.BooleanField(default=False)

    @property
    def user_id(self):
        return self.user.id

    @property
    def client_id(self):
        return self.client.id

    def delete(self):
        self.is_deleted = True

有人可以通过这段代码指出问题吗?

4

1 回答 1

0

您是否尝试像这样使用它:

Grant.objects(client_id=ObjectId("526fd0da82353536892f22ae")).first()
于 2013-11-09T06:58:46.913 回答