---
title: switchOn
description: >-
  Firestore pipelines switchOn() expression helper for switch-statement-style
  conditional logic.
next: /firestore/pipelines/timestamp-diff
previous: /firestore/pipelines/if-null
---
> ## Documentation Index
> Fetch the complete documentation index at: https://rnfirebase.io/llms.txt
> Use this file to discover all available pages before exploring further.

## Prerequisites

- `@react-native-firebase/app` installed and native config completed per [Getting Started](/).
- `@react-native-firebase/firestore` installed and rebuilt into the native app.
- A Firestore **Enterprise** database. See [Pipelines overview](/firestore/pipelines).
- Import expression helpers from `@react-native-firebase/firestore/pipelines`.
- On **iOS**, native pipeline runtime support for `switchOn` requires Firebase Apple SDK **12.12.0** or newer, which the Firebase iOS SDK version that React Native Firebase pins already satisfies.

`switchOn()` behaves like a `switch` statement: pass alternating **condition / result** pairs, plus an optional default result as the final argument when no condition matches. Without a default, a row where no condition is true makes the pipeline fail with an error instead of producing `null`, so add a default whenever the conditions are not exhaustive.

# Basic example

```js
import { getFirestore } from '@react-native-firebase/firestore';
import {
  execute,
  field,
  constant,
  equal,
  switchOn,
} from '@react-native-firebase/firestore/pipelines';

const db = getFirestore('your-enterprise-database-id');

const snapshot = await execute(
  db
    .pipeline()
    .collection('orders')
    .select(
      switchOn(
        equal(field('status'), constant(1)),
        constant('Active'),
        equal(field('status'), constant(2)),
        constant('Pending'),
        constant('Unknown'),
      ).as('statusLabel'),
    ),
);

snapshot.results.forEach(row => {
  console.log(row.data().statusLabel);
});
```

# Comparison with conditional

{/* prettier-ignore */}
| Helper | Use when |
| --- | --- |
| `conditional` | One boolean test with explicit then/else branches |
| `switchOn` | Multiple discrete cases plus optional default |

# Upstream reference

See the [firebase-js-sdk `switchOn` declaration](https://firebase.google.com/docs/reference/js/firestore_pipelines#switchon) for full overload signatures.
