Skip to main content

Class: GenericId<TableName>

values.GenericId

An identifier for a document in Convex.

Convex documents are uniquely identified by their Id, which is accessible on the _id field. To learn more, see Data Modeling.

Documents can be loaded using db.get(id) in query and mutation functions.

Important: Use myId.equals(otherId) to check for equality. Using === will not work because two different instances of Id can refer to the same document.

Ids are 16 bytes long and consist of:

  • A 14-byte random value.
  • A 2-byte timestamp representing the document's creation, in days since the Unix epoch.

This is encoded in URL-safe base 64 (uses - and _).

If you're using code generation, use the Id class typed for your data model in convex/_generated/dataModel.js.

Type parameters

NameTypeDescription
TableNameextends stringA string literal type of the table name (like "users").

Constructors

constructor

new GenericId<TableName>(tableName, id)

Type parameters

NameType
TableNameextends string

Parameters

NameType
tableNameTableName
idstring

Defined in

values/value.ts:71

Properties

tableName

Readonly tableName: TableName

The table name this GenericId references.

Defined in

values/value.ts:62


id

Readonly id: string

The identifier string.

This is encoded in URL-safe base 64 (uses - and _).

Defined in

values/value.ts:69

Methods

equals

equals(other): boolean

Check if this GenericId refers to the same document as another GenericId.

Parameters

NameTypeDescription
otherunknownThe other GenericId to compare to.

Returns

boolean

true if the objects refer to the same document.

Defined in

values/value.ts:82


fromJSON

Static fromJSON(obj): GenericId<string>

Parse a GenericId from its JSON representation.

Parameters

NameType
objany

Returns

GenericId<string>

Defined in

values/value.ts:92


toJSON

toJSON(): JSONValue

Convert a GenericId into its JSON representation.

Returns

JSONValue

Defined in

values/value.ts:110


toString

toString(): string

Convert a GenericId into its string representation.

This includes the identifier but not the table name.

Returns

string

Defined in

values/value.ts:120


inspect

inspect(): string

Pretty-print this GenericId for debugging.

Returns

string

Defined in

values/value.ts:127