Python eve ?where 查询返回空结果

标签 python mongodb rest eve

我有一个名为 Case 的 mongo 集合,其中包含以下记录:

{
    _updated: "Tue, 26 Jul 2016 10:47:34 GMT",
    user_id: "ronaldo",
    client: "webapp",
    _links: {
        self: {
            href: "case/57972a253d73f156b5427ac3",
            title: "case"
        }
    },
    _created: "Tue, 26 Jul 2016 09:15:17 GMT",
    _id: "57972a253d73f156b5427ac3",
    _etag: "e85847955b97c2a339628071397ab4cafd959062"
},
{
    _updated: "Tue, 26 Jul 2016 09:20:50 GMT",
    user_id: "578ca6e4daaf452467ffa9f2",
    client: "webapp",
    _links: {
        self: {
            href: "case/57972b723d73f156b5427ac4",
            title: "case"
        }
    },
    _created: "Tue, 26 Jul 2016 09:20:50 GMT",
    _id: "57972b723d73f156b5427ac4",
    _etag: "6a6066ed62c91d0f79bbf3a362b567f8e7710f63"
}

以下查询正确返回数据:

http://localhost:8000/case?where={"user_id":"ronaldo"}

而以下查询返回空结果集:

http://localhost:8000/case?where={"user_id":"578ca6e4daaf452467ffa9f2"}

Please note that If I do the query directly in mongo, it works:

db.case.find({user_id: "578ca6e4daaf452467ffa9f2"})

请帮忙!

最佳答案

看起来您的 user_id 有时可能包含类似 objectid 的字符串。尝试在资源设置中设置query_objectid_as_string。引用 docs :

When [query_objectid_as_string is] enabled the Mongo parser will avoid automatically casting electable strings to ObjectIds. This can be useful in those rare occurrences where you have string fields in the database whose values can actually be casted to ObjectId values, but shouldn’t. It effects queries (?where=) and parsing of payloads. Defaults to False.

关于Python eve ?where 查询返回空结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38627492/

相关文章:

MongoDB:如何使用查找查询填充嵌套对象?

php - YII 在 REST GET 请求中获取请求体

python - 立即显示 matplotlib 中图形的内容

python - Python 中的 is 运算符

python - Django RSS-feed 转义 €

mysql - 可以在 Rails 中配置模型以从不同的数据源提取数据吗?

python - 将 Linux 命令从一台机器发送到另一台机器的最佳方法是什么?

java - 吗非亚/MongoDB : can't do getmore

api - 基于 Web 的 REST API 浏览器(资源管理器、导航器、漫游器)?

rest - Magento 2 REST API 获取所有产品