Searching

Most routes use the same standard methods for performing searches. There is a simple search and an advanced search.

Basic search

The basic search can be performed on most routes' standard ‘index’ route (i.e. any route which uses a GET on the base model uri e.g. ‘/api/conditions’ and which calls the index method).

For example, if we wished to perform a simple search on the products list using some pagination, we can append a search query: GET /api/products?limit=25&skip=0&search=udder

This will return all documents in the products collection which contains the string ‘udder’.

Advanced Search

The advanced search queries accept the request body object as an argument. This function checks for an array in each field of the request body and then assembles the query for that field appropriately. This allows one or more fields to contain multiple search values regardless of whether that field is represented as an array in the db collection.

For example to return all conditions where organ equals udder or eye and route_of_admin equals topical we would POST the following JSON to POST /api/conditions/search?limit=25&skip=0

    
{
   "organ": ["udder","eye"],
   "route_of_admin": ["topical"]
}