def _get_ordering(son):
    def fmt(field, direction):
        return '{0}{1}'.format({-1: '-', 1: '+'}[direction], field)

    if '$orderby' in son:
        return ', '.join(fmt(f, d) for f, d in son['$orderby'].items())

# Taken from Django Debug Toolbar 0.8.6
Helper function to extract formatted ordering from dict.
dataset/ETHPy150Open hmarr/django-debug-toolbar-mongo/debug_toolbar_mongo/operation_tracker.py/_get_ordering