Sort

Sorting can be applied to indexed properties, or to any named property when a grouping is applied. The value can be a single property name sort=total, or a JSON object containing
one or more property names with either 1 (ascending) or -1 (descending) as the value.

?where={<query conditions>}&sort=<property>

Or when specifying the sort order:

?where={<query conditions>}&sort={<property>: <sort order>}

Or sorting by multiple properties:

?where={<query conditions>}&sort={<property1>: <sort order>, <property2>: <sort order>, ...}

Examples

The following shows an example of sorting a list of accounts by last name then by first name.

GET /accounts/?paths[]=name&sort={"name.last": 1, "name.first": 1}
{                
    "data": [
        {
            "_id": "507f1f77bcf86cd799439011",
            "name": {
                "first": "John",
                "last": "Smith"
            },
            "object": "account"
        },
        {
            "_id": "55ff9db67a00a89c14aa31a6",
            "name": {
                "first": "Stan",
                "last": "Smith"
            },
            "object": "account"
        },
        {
            "_id": "507f191e810c19729de860ea",
            "name": {
                "first": "Jane",
                "last": "Svenson"
            },
            "object": "account"
        },                        
        ...  
  ],
  "hasMore": true,
  "object": "list"
}