我正在使用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
有人可以通过这段代码指出问题吗?