【发布时间】:2023-02-10 03:00:31
【问题描述】:
我需要使用 mongo 执行 mongodb find_one 查询但得到 AttributeError: 'NoneType' object has no attribute 'hint' 因为没有匹配过滤器的结果
db.collection_name.find_one( filter=filter_query, projection={ _id: False, date: True, }, sort=[ ( date, pymongo.DESCENDING, ) ], ).hint('some_index')
也试过
db.collection_name.find_one( filter=filter_query, projection={ _id: False, date: True, }, sort=[ ( date, pymongo.DESCENDING, ) ], hint='some_index'
)
我知道我可以用 find() 做到这一点,但是有没有办法用 find_one 做到这一点?
【问题讨论】:
-
您显示的第二个
find_one的输出/错误是什么?
标签: pymongo