Collection: delete() method

Available since @irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room host

The delete() method of the Collection interface deletes an entry and resolves with whether it existed.

Syntax

delete(id)
delete(id, options)

Parameters

id
The entry’s ID.
options Optional

An object with any of these properties:

version
The version the entry must have, or the delete fails with E_VERSION.
once
A key that makes the delete safe to repeat, as for PlayerData.set().

Return value

A Promise that resolves with true if the entry existed, or false.

Exceptions

The promise rejects with a DataError, such as E_VERSION when the entry doesn’t have the version given.

Examples

Clearing a finished game from players’ lists

// game-over.ts
import { defineRoom } from "@irtio/room";

export default defineRoom({
  async onPlayerLeave(room, player) {
    const games = room.collection("games");
    const { entries } = await games.list({ owner: player, where: { room: room.id } });
    for (const entry of entries) await games.delete(entry.id);
  },
});

See also

Runtime availability

Hosted roomsirt dev@irtio/testingSelf-hosted room host
delete()0.10.10.10.1