我有一个 MongoEngine 文档类学生..
class Student(Document):
db_id = StringField()
name = StringField()
score = IntField()
deleted = BooleanField(default=False, required=True)
我想查询为
Student.objects.filter(score__gte=30)
但是我收到了一个错误,比如AttributeError: 'int' object has no attribute 'get'
有人可以帮助我如何做到这一点吗?谢谢!
以下(最小)片段工作正常
from mongoengine import *
connect()
class Student(Document):
name = StringField()
score = IntField()
Student(name='Bob', score=35).save()
print(Student.objects(score__gte=30))
# output: [<Student: Student object>]
我运行您的代码没有任何问题,也许从我的代码开始并在此基础上构建,直到您确定罪魁祸首。我还建议在测试之前删除现有的 mongo 集合。
事实上,根据触发错误的位置(我们没有堆栈跟踪所以我们无法判断),可能是在将现有的 mongo 文档(由您的查询返回)加载到 Student 构造函数中时失败
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句