switchOn

Pipeline expression helper that picks a result from the first matching condition.

switchOn() behaves like a switch statement: pass alternating condition / result pairs, plus an optional default result as the final argument when no condition matches.

Import from the pipelines entry point:

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

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

HelperUse when
conditionalOne boolean test with explicit then/else branches
switchOnMultiple discrete cases plus optional default

On iOS, the native pipeline runtime evaluates switchOn on Firebase iOS SDK 12.12.0+ (RNFB pins 12.15.0); unified cross-platform e2e.

Upstream reference

See the firebase-js-sdk switchOn declaration for full overload signatures.

On this page