mongodb
我从实例中获取对象时遇到问题。如果我用接口搜索这个对象pymongo
,一切都很好——可以找到对象。如果尝试用pymodm
- 做同样的事情,它会失败并出现错误。
这是我正在做的事情:
from pymodm import connect, MongoModel, fields
from pymongo import MongoClient
class detection_object(MongoModel):
legacy_id = fields.IntegerField()
client = MongoClient(MONGODB_URI)
db = client[MONGODB_DEFAULT_SCHEME]
collection = db['detection_object']
do = collection.find_one({'legacy_id': 1437424})
print(do)
connect(MONGODB_URI)
do = detection_object.objects.raw({'legacy_id': 1437424}).first()
print(do)
第一个打印输出:{'_id': ObjectId('5c4099dcffa4fb11494d983d'), 'legacy_id': 1437424}
. 但是,在执行此命令期间:do = detection_object.objects.raw({'legacy_id': 1437424}).first()
解释器失败并出现以下错误:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/pymodm/queryset.py", line 127, in first
return next(iter(self.limit(-1)))
StopIteration
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/konsof01/PycharmProjects/testthisfuckingshit/settings.py", line 29, in <module>
do = detection_object.objects.raw({'legacy_id': 1437424}).first()
File "/usr/local/lib/python3.7/site-packages/pymodm/queryset.py", line 129, in first
raise self._model.DoesNotExist()
__main__.DoesNotExist
怎么会这样?我正在尝试使用相同的连接和集合查询相同的对象。请问有什么想法吗?