Skip to content

[BUG] RTDB & Firestore query filter should preserve number vs string types (no incorrect coercion) #46

@omer-ayhan

Description

@omer-ayhan

Bug Description

RTDB and Firestore query filters (e.g., equalTo, startAt, endAt, and Firestore where queries) can behave incorrectly when the filter value is intended to be a number but is treated as a string (or vice-versa). This causes missing/incorrect matches in both RTDB and Firestore. For example, when querying Firestore for a string written as a number (e.g., a field with value "5"), queries using the number 5 will not match, and vice versa. This can lead to confusing or incorrect query results.

Steps to Reproduce

RTDB Example

  1. Prepare RTDB data where a child value is numeric, e.g.:
    • users/u1/age = 10 (number)
  2. Run a query command that filters with value 10, which sometimes gets treated as "10" (string).
  3. Observe results do not match expectations, especially for numeric comparisons.

Firestore Example

  1. Save a document field value as a string-encoded number, e.g., { "value": "5" } (note the string type).
  2. Run a filter/query with value 5 (number), expecting to match, but it does not match. The inverse (string vs number) yields the same issue.

Expected Behavior

  • Query filters should use the actual intended type:
    • equalTo(10) matches numeric 10 in RTDB.
    • Numeric startAt/endAt perform correct numeric ordering.
    • Firestore queries should distinguish and respect the intended type (number vs string) for matching.
  • Provide an unambiguous way to pass typed values (e.g., JSON literal input or explicit --type number|string|boolean|null).

Actual Behavior

  • Filter values may be coerced or parsed in a way that changes the type, producing incorrect results for both RTDB and Firestore queries.
  • Querying with a string that looks like a number ("5") will not match a number (5), and vice versa, even if the content is identical.

Environment

  • OS: [e.g. macOS, Ubuntu]
  • Node.js version: [e.g. 18.17.0]
  • firebase-tools-cli version: [e.g. 0.5.1]

Additional Context

Suggested Implementation Notes

  • Prefer explicit typing:
    • --value-json '10' vs --value-json 10
    • or --value 10 --type number
  • Add tests for numeric vs string stored values with equalTo/startAt/endAt (RTDB), and for Firestore filters comparing strings that look like numbers with true numbers, both directions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions