4

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

Rodrigo
  • 135
  • 4
  • 45
  • 107

2 Answers2

14

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.

Nicola Iarocci
  • 6,606
  • 1
  • 20
  • 33
  • Thanks for your reply! But what I really need is the $text operator (fulltext search). I think this is was not implemented yet, I'll fork and sent a pull request soon – Rodrigo Apr 16 '14 at 13:50
  • @Skhaz , how did the work with the $text operator go? – mgmonteleone Jan 01 '15 at 15:45
  • Could this also be done by defining an 'additional_lookup' for the schema in settings.py? – mhumesf Aug 27 '15 at 23:05
0

I am not conversant with Eve myself. But looking at it's webpage seems like it exposes all of Flask's functionalities.

You need to be looking at this page in the documentation that talks about accessing the request data.

In your Flask app, define a method that accepts both POST and GET requests and then you can access foo by doing request.args.get('contains', '').

This is what I mean:

@app.route('/people', methods=['POST', 'GET'])
def get_people():
    search_key = request.args.get('contains', '')
    #search for people containing 'foo' in your DB

Hope this gives you a starting point as to how to go about things.

shaktimaan
  • 11,962
  • 2
  • 29
  • 33