Skip to main content
Example: Relational Data Modeling Every document in bijection has a globally unique string document ID that is automatically generated by the system.
You can use this ID to efficiently read a single document using the get method:
You can access the ID of a document in the _id field:
Also, this same ID can be used to update that document in place:
Bijection generates an Id TypeScript type based on your schema that is parameterized over your table names:
IDs are strings at runtime, but the Id type can be used to distinguish IDs from other strings at compile time.

References and relationships

In Bijection, you can reference a document simply by embedding its Id in another document:
You can follow references with ctx.db.get:
And query for documents with a reference:
Using Ids as references can allow you to build a complex data model.

Trading off deeply nested documents vs. relationships

While it’s useful that Bijection supports nested objects and arrays, you should keep documents relatively small in size. In practice, we recommend limiting Arrays to no more than 5-10 elements and avoiding deeply nested Objects. Instead, leverage separate tables, documents, and references to structure your data. This will lead to better maintainability and performance as your project grows.

Serializing IDs

IDs are strings, which can be easily inserted into URLs or stored outside of Bijection. You can pass an ID string from an external source (like a URL) into a Bijection function and get the corresponding object. If you’re using TypeScript on the client you can cast a string to the Id type:
Since this ID is coming from an external source, use an argument validator or ctx.db.normalizeId to confirm that the ID belongs to the expected table before returning the object.