currentDocument

Firestore pipelines currentDocument() expression helper: reference the document being processed, typically inside a select() stage.

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.
  • Import expression helpers from @react-native-firebase/firestore/pipelines.

currentDocument() returns an expression representing the Firestore document row the pipeline is processing. Use it when you need the full document map in a projection or when binding the document to a variable in upstream firebase-js-sdk samples.

Basic example

Read a field from the document map with mapGet:

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

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

const snapshot = await execute(
  db
    .pipeline()
    .collection('books')
    .select(mapGet(currentDocument(), 'title').as('title'), field('author').as('author')),
);

snapshot.results.forEach(row => {
  console.log(row.data().title, row.data().author);
});

Upstream define-stage pattern

The firebase-js-sdk also shows binding the document with a define stage. React Native Firebase exposes the same define stage and variable() helper. Bind the document, then read fields with mapGet(variable('doc'), 'fieldName'). For a direct projection without a named binding, prefer mapGet(currentDocument(), 'fieldName') as in the Basic example above.

currentDocument() is typed as Expression, so the sample uses a JSDoc cast to FunctionExpression before calling .as(); .as() is not on every Expression.

js
import { getFirestore } from '@react-native-firebase/firestore';
import {
  currentDocument,
  execute,
  mapGet,
  variable,
} from '@react-native-firebase/firestore/pipelines';

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

const currentDoc =
  /** @type {import('@react-native-firebase/firestore/pipelines').FunctionExpression} */ (
    currentDocument()
  );

const snapshot = await execute(
  firestore
    .pipeline()
    .collection('books')
    .define(currentDoc.as('doc'))
    .select(mapGet(variable('doc'), 'title')),
);

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

Platform support

{/* prettier-ignore */}

PlatformSupport
AndroidSupported (native Firestore SDK)
iOSSupported (native Firestore SDK)
macOSSupported (firebase-js-sdk web interop)

Pipeline execution requires a Firestore Enterprise database. See Pipelines overview.

On this page