ifNull

Pipeline expression helper that returns a fallback when a value is null or absent.

ifNull() returns a fallback when the first argument evaluates to null or is absent. Unlike ifAbsent(), which only substitutes missing fields, ifNull() also replaces explicit null values stored on the document.

Import from the pipelines entry point:

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

Basic example

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

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

const snapshot = await execute(
  db
    .pipeline()
    .collection('users')
    .select(ifNull(field('displayName'), constant('Anonymous')).as('displayName')),
);

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

Fluent form

js
field('displayName').ifNull(constant('Anonymous')).as('displayName');

Comparison with ifAbsent

HelperMissing fieldExplicit null on document
ifAbsentfallbackkeeps null
ifNullfallbackfallback

Use ifNull when you want one expression to cover both absent and null values.

Upstream reference

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

On this page