CipherStash
CipherStash Documentation

Ordering

A second argument can be passed to .query(), which allows you to pass a keyword argument for ordering.

{
    order: [
        { byIndex: "runningTime", direction: "ASC" }
    ]
}

byIndex: The index to apply the ordering to.

direction: ASC (ascending) or DESC (descending)

Any range index can be used for sorting results.

import { Stash } from "@cipherstash/stashjs"
import { generateSchemaWithMapping } from "./schemaWithMapping";

const matchQuery = async () => {
    try {
        const stash = await Stash.connect();

        const movieSchema = await generateSchemaWithMapping()

        const movies = await stash.loadCollection(movieSchema)

        const queryResult = await movies.query(
          movie => movie.title.match("ody"),
          {
            order: [
              {byIndex: "runningTime", direction: "DESC"}
            ]
          }
        )


        console.log(queryResult)
        return queryResult
      } catch (err) {
        console.error(err)
        console.error(`Could not query collection! Reason: ${JSON.stringify(err)}`)
        return
      }
}

matchQuery()