Docs Menu

Docs HomeRealm

CRUD - Node.js SDK

On this page

  • Transaction Lifecycle

A write transaction is a function that modifies objects in a realm. Write transactions let you create, modify, or delete Realm objects. They handle operations in a single, idempotent update. A transaction is all or nothing. Either:

  • All the operations in the transaction succeed, or;

  • If any operation fails, none of the operations complete.

Important

Every write operation must occur in a write transaction.

Write transactions are callback functions that you pass to a realm instance. For examples of specific write operations, see CRUD - Node.js SDK.

For example, assuming we already have a Realm object called task1, we can modify task1's status property by writing to the object.

realm.write(() => {
task1.status = "InProgress";
});

A given realm only processes one write transaction at a time. When you make a write transaction, the realm adds the transaction to a queue. The realm evaluates each transaction in the order it arrived.

After processing a transaction, Realm Database either commits it or cancels it:

  • After a commit, the realm applies all operations in the transaction. Once applied, the realm automatically updates live queries. It notifies listeners of created, modified, and deleted objects.

    Note

    When using Sync, the SDK also queues the changes to send to Atlas App Services. The SDK sends these changes when a network is available.

  • Realm Database does not apply any operations in a cancelled transaction. Realm Database cancels a transaction if an operation fails or is invalid.

←  Embedded Objects - Node.js SDKCRUD - Create - Node.js SDK →
Share Feedback
© 2023 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2023 MongoDB, Inc.