我有一个名为 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/