FirebaseFirestore Framework Reference

ConditionalExpression

public class ConditionalExpression : FunctionExpression, @unchecked Sendable

A ConditionalExpression is a FunctionExpression that evaluates to one of two expressions based on a boolean condition.

This is equivalent to a ternary operator (condition ? then : else).

Example of using ConditionalExpression:

// Create a new field "status" based on the "rating" field.
// If rating > 4.5, status is "top_rated", otherwise "regular".
firestore.pipeline()
  .collection("products")
  .addFields([
    ConditionalExpression(
      Field("rating").greaterThan(4.5),
      then: Constant("top_rated"),
      else: Constant("regular")
    ).as("status")
  ])