CipherStash
CipherStash Documentation

Exact query

An exact query means this will be an equality query.

In this example we indexed the field exactTitle as an exact index type on the record field title.

Unlike the match query, only records with exactly the same value will be returned.

import {
  Stash,
  StashRecord,
} from "@cipherstash/stashjs"

interface Movie extends StashRecord {
  title: string;
  runningTime: number;
  year: number;
};

const exactQuery = async () => {
    try {
        const stash = await Stash.connect()
        const movies = await stash.loadCollection<Movie>("movies")

        const queryResult = await movies.query(movie => movie.exactTitle.eq("The Odyssey"))

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

exactQuery()

This query returns the below result.

{
  took: 0.087564917,
  documents: [
    {
      titleType: 'movie',
      primaryTitle: 'The Odyssey',
      originalTitle: 'Al-Oudyssa',
      startYear: 2004,
      runtimeMinutes: 92,
      genres: 'Crime,Drama,Thriller',
      year: 2004,
      title: 'The Odyssey',
      runningTime: 92
    }
  ],
  aggregates: []
}

In the below example searching on just the word Odyssey will not return any results.

import {
  Stash,
  StashRecord,
} from "@cipherstash/stashjs"

interface Movie extends StashRecord {
  title: string;
  runningTime: number;
  year: number;
};

const exactQuery = async () => {
    try {
        const stash = await Stash.connect()
        const movies = await stash.loadCollection<Movie>("movies")

        const queryResult = await movies.query(movie => movie.exactTitle.eq("Odyssey"))

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

exactQuery()
{ took: 0.056357083, documents: [], aggregates: [] }