CipherStash
CipherStash Documentation

Update record

The put API performs an upsert on the record.

If the record ID provided in the request matches with an existing record ID, that record will be updated.

import { Stash, StashRecord } from "@cipherstash/stashjs";
import { v4 as uuidv4 } from "uuid";

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

export const updateRecord = async (): Promise<string> => {
  try {
    const stash = await Stash.connect();
    const movies = await stash.loadCollection<Movie>("movies");
    const existingRecordId = "b5038eb1-c316-4032-8dcc-a2d36d5411c6"

    const id = await movies.put({
      id: existingRecordId,
      title: "The Matrix",
      year: 1999,
      runningTime: 136,
    });

    console.info(`Updated record ${id}`);
    return id;
  } catch (err) {
    console.error(`Failed to updated record. Reason: ${describeError(err)}`);
  }
};

updateRecord();