简体   繁体   中英

Not able to fetch mongodb object with a valid field

I'm using Mongoengine. When I do a:

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

The result is as expected.

ObjectId('526fd0da82353536892f22ae')

But, when I search based on the client_id ,

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

I get a InvalidQueryError:

InvalidQueryError: Cannot resolve field "client_id" Here's what my Grant model looks like:

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

Can someone go through this code and point out the problem?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM