Query with --orderby

When querying JSON documents with the find command, you can use the --orderby option to order the data. You can specify either an ascending or descending sort using the keywords, ASC and DESC.

General Syntax

find <table path> --orderby <field path>:<sortorder>

The keywords ASC and DESC are case insensitive. Ascending is the default sort order.

Sample JSON Document

The following sample JSON document is used in examples in this section:

{
    "_id": "id1",
    "a": {
            "b": [{"boolean":false}, {"decimal": 123.456}],
            "c":{
                  "d":10,
                  "e":"Hello"
                 }
          },
    "m":"MapR wins"
}       

Simple Sort

The following syntax and example are a simple sort on a single field path in the default ascending sort order:

// Syntax
find <table path> --orderby <field path>

// Example
find /tbl --orderby a.c.d

Specific Sort on Single Field

The following syntax and example are a sort with a specified ordering on a single field path:

// Syntax
find <table path> --orderby <field path>:<sort order>

// Example
find /tbl --orderby a.c.d:desc

Specific Sort on Multiple Fields

The following syntax and example specify a sort ordering on each field path:

// Syntax
find <table path> --orderby <field path>:<sort order>,<field path>:<sort order>

// Example
find /tbl --orderby a.c.d:asc,a.c.e:desc

Mixed Mode Sort on Multiple Fields

The following syntax and example specify a sort ordering on one field path and use the default sort order (ascending) on another field path.

// Syntax
find <table path> --orderby <field path>:<sort order>,<field path>

// Example
find /tbl --orderby a.c.d:DESC,a.c.e