Skip to content
Back

DATA LOSS when using DB Operators in transactions

  • 0
  • Databases
  • Cloud
Lysine
9 Nov, 2025, 10:46

I'm using Appwrite Cloud with TablesDB. Calling updateRow with DB operators work as expected:

TypeScript
await databases.updateRow({
  databaseId: 'db-id',
  tableId: 'table-id',
  rowId: '123',
  data: {
    items: Operator.arrayRemove(oldId),
  },
});
await databases.updateRow({
  databaseId: 'db-id',
  tableId: 'table-id',
  rowId: '123',
  data: {
    items: Operator.arrayInsert(2, newId),
  },
});

But staging these updates in a transaction causes the entire items array to be set to null:

TypeScript
const transaction = await databases.createTransaction();
await databases.updateRow({
  databaseId: 'db-id',
  tableId: 'table-id',
  rowId: '123',
  transactionId: transaction.$id,
  data: {
    items: Operator.arrayRemove(oldId),
  },
});
await databases.updateRow({
  databaseId: 'db-id',
  tableId: 'table-id',
  rowId: '123',
  transactionId: transaction.$id,
  data: {
    items: Operator.arrayInsert(2, newId),
  },
});
await databases.updateTransaction({
  transactionId: transaction.$id,
  commit: true
});

Staging these updates via createOperations also doesn't work, but it only throws an error instead of damaging existing data:

TypeScript
await databases.createOperations({
  transactionId: 'transaction-id',
  operations: [
    {
      action: 'update',
      databaseId: 'db-id',
      tableId: 'table-id',
      rowId: '123',
      data: {
        items: Operator.arrayRemove(oldId),
      }
    },
    {
      action: 'update',
      databaseId: 'db-id',
      tableId: 'table-id',
      rowId: '123',
      data: {
        items: Operator.arrayInsert(2, newId),
      }
    }
  ]
});

The returned error is:

TypeScript
AppwriteException: Invalid document structure: Attribute "items" must be an array
     code: 400,
     type: "document_invalid_structure",
 response: "{\"message\":\"Invalid document structure: Attribute \\\"items\\\" must be an array\",\"code\":400,\"type\":\"document_invalid_structure\",\"version\":\"1.8.0\"}",
TL;DR
Developers are experiencing data loss when using DB operators in transactions with TablesDB. Attempting to update rows with these operators within a transaction setting causes the entire 'items' array to be set to null. Using `createOperations` method throws an error instead of altering data. The issue is linked to incompatible types or incorrect usage of DB operators, but there is limited documentation. Developers should verify the structure compatibility of DB operators with the TableDB to prevent data loss.
Lysine
9 Nov, 2025, 10:51

Maybe I'm using DB operators wrong but documentation is limited and the typescript typings in node-appwrite are even unusable (cannot assign string Operators to columns of incompatible types). In any case, I'm surprised that this behavior isn't caught and fixed pre-release

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more