toFirestoreValue()function

toFirestoreValue(value: unknown, caller: AnyCaller = toFirestoreValue): FirestoreValue
ParamType
valueunknown
The value to convert (null, boolean, string, finite number, array, or plain object). required
callerAnyCaller
Caller function used to attribute thrown errors. Defaults to toFirestoreValue
Return
FirestoreValue
The Firestore JSON value.
Throws
unknown
ValueError if the value cannot be represented (e.g. undefined, functions, non-finite numbers, class instances).

Convert a data value to its Firestore REST API JSON representation.

  • Safe integers become integerValue (which the REST API encodes as a string), other finite numbers become doubleValue.
  • Arrays and plain objects convert recursively.

Examples

toFirestoreValue(123) // { integerValue: "123" }