Collection: put() method

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

The put() method of the Collection interface creates an entry or replaces the whole of one, and resolves with its ID and version.

Syntax

put(entry)

Parameters

entry

An object with these properties:

id Optional
The entry’s ID, 1 to 64 of A-Z a-z 0-9 _ . : -. Without one, the data service makes one up.
value
JSON, or a Uint8Array, at most 64 KB.
meta Optional
Flat strings, numbers and booleans to filter on, at most 1 KB.
score Optional
A number to sort on, or null.
owner Optional
The player who owns the entry, or null.
version Optional
The version the entry must have, or the write fails with E_VERSION. 0 means it must not exist.
once Optional
A key that makes the write safe to repeat, as for PlayerData.set().

Return value

A Promise that resolves with { id, version }.

Exceptions

The promise rejects with a DataError whose code is, among others:

E_VERSION
The entry doesn’t have the version given.
E_QUOTA
The collection holds 1,000,000 entries.
E_UNKNOWN
The collection isn’t declared in the live build, or is the wrong kind for the call.

Description

put() replaces the whole entry and keeps its created time: meta, score and owner left out become empty. So pass owner on every put() of an entry a player owns, or the entry loses its owner, and with it its place in that player’s lists.

Examples

Recording each player’s game in an async match

// seats.ts
import { defineRoom } from "@irtio/room";

export default defineRoom({
  async onMessage(room, connection, message) {
    if (message !== "end-turn") return;
    await room.collection("games").put({
      id: `${room.id}.${connection.data.seat}`,
      value: null,
      owner: connection.player,
      meta: { room: room.id, status: "active", yourTurn: false },
    });
  },
});

See also

Runtime availability

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