Skip to main content

Class: GenericId<TableName>

values.GenericId

An identifier for a document in Convex.

Convex documents are uniquely identified by their GenericId, 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 GenericId can refer to the same document.

GenericIds are 17 bytes long and consist of:

  • A 15-byte random value.
  • A 2-byte timestamp representing the document's creation, in days since the Unix epoch. This is encoded in base 62 ([0-9A-Za-z]).

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").

Properties

tableName

Readonly tableName: TableName

The table name this GenericId references.


id

Readonly id: string

The identifier string.

This contains the characters [0-9A-Za-z].

Constructors

constructor

new GenericId<TableName>(tableName, id)

Type parameters

NameType
TableNameextends string

Parameters

NameType
tableNameTableName
idstring

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.


fromJSON

Static fromJSON(obj): GenericId<string>

Parse a GenericId from its JSON representation.

Parameters

NameType
objany

Returns

GenericId<string>


toJSON

toJSON(): JSONValue

Convert a GenericId into its JSON representation.

Returns

JSONValue


toString

toString(): string

Convert a GenericId into its string representation.

This includes the identifier but not the table name.

Returns

string


inspect

inspect(): string

Pretty-print this GenericId for debugging.

Returns

string