Home / Companies / Firebase / Blog / Post Details
Content Deep Dive

Converting between Firestore FieldValue and Variant

Blog post from Firebase

Post Details
Company
Date Published
Author
Konstantin Varlamov
Word Count
2,533
Company Posts That Month
4
Language
English
Hacker News Points
-
Post removed?
No
Summary

Firestore’s C++ SDK uses FieldValue for Firestore document data, while Variant serves similar roles across other Firebase C++ SDKs such as Realtime Database, Remote Config, and Cloud Functions; although they share primitive types, strings, blobs, arrays, and maps, neither fully encompasses the other, making complete generic conversion impossible. Primitive values convert directly, while string and blob conversion must account for Variant’s ownership distinctions, and arrays and maps can generally be converted recursively, subject to Firestore’s requirement that map keys be strings. Firestore’s prohibition on nested arrays requires application-specific handling, such as rejecting or omitting them, encoding arrays as maps, or using marked intermediary maps to preserve round-trip conversion. Firestore-only types including timestamps, geographic points, document references, and certain sentinel values can be represented as specially marked maps when bidirectional conversion is needed, though document references require access to a Firestore instance and timestamps may instead be represented as epoch milliseconds for Realtime Database compatibility. Stateless sentinels such as Delete and ServerTimestamp can be mapped to compatible representations, but stateful operations such as array unions, removals, and increments cannot be converted losslessly because their underlying values are inaccessible.

Trends Found in this Post

No tracked trend matches for this post yet.

Use This Data

Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.