diff --git a/spaceweather_processing/app.py b/spaceweather_processing/app.py index 93fde0bd315645cb935b82af420db41e1c0f4746..b8c3a221cde94fd66f386b317be8c5b6067a27b4 100644 --- a/spaceweather_processing/app.py +++ b/spaceweather_processing/app.py @@ -136,8 +136,14 @@ class DataProductDB: # if a &sort=<field> url parameter is given then use sort, otherwise omit it (backward compatibility) if sort: + if sort.startswith('-'): + direction = -1 + sort = sort.lstrip('-') + else: + direction = 1 + results = [augment_item(item) for item in - self.db[collection_name].find(query, selected_fields).skip(skip).limit(limit).sort(sort)] + self.db[collection_name].find(query, selected_fields).skip(skip).limit(limit).sort(sort,direction)] else: results = [augment_item(item) for item in self.db[collection_name].find(query, selected_fields).skip(skip).limit(limit)]