02 / 10

What is core api and callback api?

In MongoDB, the Core API and Callback API are approaches to handle transactions, enabling operations across multiple documents or collections as a single atomic unit. Here’s an explanation of both and their differences

Core API: The Core API is a lower-level interface for managing MongoDB transactions. It provides explicit control over the transaction lifecycle, requiring developers to:
  1. 1

    Start a transaction.

  2. 2

    Handle errors manually.

  3. 3

    Commit or abort the transaction explicitly.

javascript
Callback API: The Callback API is a higher-level abstraction that simplifies transaction management. It automates aspects like retrying on transient errors and handling unknown commit results.
  1. 1

    Reduces developer effort by automating retries and commit handling

  2. 2

    Recommended for most general use cases to simplify transaction workflows.

  3. 3

    Automatically incorporates error-handling logic for TransientTransactionError and UnknownTransactionCommmitResult.

javascript