---
title: ifNull
description: >-
  Firestore pipelines ifNull() expression helper: provide a fallback value when
  a field is null or absent, contrasted with ifAbsent().
next: /firestore/pipelines/switch-on
previous: /firestore/pipelines/current-document
---
> ## 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`.

`ifNull()` returns a fallback when the first argument evaluates to **null** or is **absent**. Unlike `ifAbsent()` (shown [below](#comparison-with-ifabsent)), which only substitutes missing fields, `ifNull()` also replaces explicit `null` values stored on the document.

# 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

The same expression can be built from the field helper:

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

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

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

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

# Comparison with ifAbsent

{/* prettier-ignore */}
| Helper | Missing field | Explicit `null` on document |
| --- | --- | --- |
| `ifAbsent` | fallback | keeps `null` |
| `ifNull` | fallback | fallback |

Use `ifNull` when you want one expression to cover both absent and null values. `ifAbsent` takes the same arguments (an expression or field name, then a fallback expression or value) and comes from the same entry point. It is typed as a plain `Expression`, which has no `.as()`, so wrap it in another helper such as `toUpper` before aliasing:

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

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

const snapshot = await execute(
  db
    .pipeline()
    .collection('users')
    .select(toUpper(ifAbsent(field('nickname'), constant('No nickname'))).as('nickname')),
);

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

# Upstream reference

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