Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Eve contains filter

There's some way to return items that field contains some value? Eg.

GET /people?contains="foo"

Return all persons that have the word 'foo' in the name.

Thanks in advance

like image 776
Rodrigo Avatar asked Dec 09 '22 08:12

Rodrigo


1 Answers

You could use mongodb $regex operator, which is blacklisted by default in Eve (MONGO_QUERY_BLACKLIST = ['$where', '$regex']).

Add MONGO_QUERY_BLACKLIST = ['$where'] to your settings.py. Then you can query your API like this:

?where={"name": {"$regex": ".*foo.*"}}.

Be careful however. If you don't control the client, enabling regexes could potentially increase your API vulnerability.

like image 61
Nicola Iarocci Avatar answered Jan 01 '23 12:01

Nicola Iarocci