Raptor Raptor - 4 months ago 26
Python Question

Python eve ?where query returns empty result

I have a mongo collection called Case which has the following records:

{
_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"
}


The following query returns data correctly:

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


whereas the following query returns empty result set:

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"})



Please help!

Answer

It looks like your user_id can sometimes contain objectid-like strings. Try setting query_objectid_as_string in your resource settings. Quoting the 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.

Comments