On the client, PowerSync only supports a single primary key column called id
, of type text
.
id
. Use the uuid()
helper to generate a random UUID (v4) on the client.ObjectId
for _id
. Generate an ObjectId()
in your app code and store it in the client’s id
column as a string; this will map to MongoDB’s _id
._id
as the name of the ID field in collections. Therefore, PowerSync requires using SELECT _id as id
in Sync Rule’s data queries when using MongoDB as the backend source database. When inserting new documents from the client, prefer ObjectId
values for _id
(stored in the client’s id
column).uploadData()
isn’t blindly using a field named id
when handling CRUD operations. See the Sequential ID mapping tutorial for an example where the record ID is aliased to uuid
on the backend.sequence
type in Postgres), the issue is that the ID can only be generated on the server, and not on the client while offline. If this must be used, there are some options, depending on the use case.
id
field, then generate a new ID when the server receives it.