Bird
Raised Fist0
Firebasecloud~10 mins

Supported data types in Firebase - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Supported data types
Start: Define Data
↓
Check Data Type
↓
String
↓
Store in DB
↓
Retrieve & Use
↓
End
Data is defined, its type is checked among supported types, then stored and retrieved from Firebase.
Execution Sample
Firebase
docRef.set({
  name: "Alice",
  age: 30,
  isMember: true
});
Stores a document with string, number, and boolean data types in Firebase.
Process Table
StepData FieldValueDetected TypeAction
1name"Alice"StringStore as string
2age30NumberStore as number
3isMembertrueBooleanStore as boolean
4All fieldsN/AN/ADocument stored successfully
5RetrieveN/AN/AData retrieved with original types
💡 All supported data types stored and retrieved correctly.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
nameundefined"Alice""Alice""Alice""Alice"
ageundefinedundefined303030
isMemberundefinedundefinedundefinedtruetrue
Key Moments - 2 Insights
Why does Firebase store numbers without quotes but strings with quotes?
Because Firebase detects the data type by the value format: quotes mean string, no quotes with digits mean number, as shown in execution_table steps 1 and 2.
Can I store a boolean value as a string to represent true/false?
You can, but Firebase treats it as a string, not a boolean. See execution_table step 3 where true is stored as a boolean, not a string.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what type is the 'age' field detected as at step 2?
AString
BNumber
CBoolean
DUndefined
💡 Hint
Check the 'Detected Type' column for step 2 in the execution_table.
At which step is the boolean value stored in Firebase?
AStep 3
BStep 2
CStep 1
DStep 4
💡 Hint
Look for the 'isMember' field in the execution_table.
If you changed the 'age' value to "30" (with quotes), how would the detected type change?
AIt would remain Number
BIt would become Boolean
CIt would become String
DIt would be Undefined
💡 Hint
Refer to how quotes affect type detection in execution_table steps 1 and 2.
Concept Snapshot
Firebase supports these data types:
- String: text in quotes
- Number: digits without quotes
- Boolean: true or false
Store data by type; Firebase keeps types on retrieval.
Use correct types to avoid errors.
Full Transcript
In Firebase, data is stored with clear types: strings, numbers, and booleans. When you save a document, Firebase checks each field's value to detect its type. For example, text inside quotes is a string, digits without quotes are numbers, and true/false are booleans. This ensures data is stored correctly and can be retrieved with the same type. The example shows storing a name as a string, age as a number, and membership status as a boolean. Understanding these types helps avoid confusion and errors when working with Firebase data.

Practice

(1/5)
1. Which of the following is NOT a supported data type in Firebase Firestore?
easy
A. String
B. Function
C. Boolean
D. GeoPoint

Solution

  1. Step 1: Review Firebase supported data types

    Firebase supports strings, booleans, numbers, arrays, maps, timestamps, and geopoints.
  2. Step 2: Identify unsupported type

    Functions are not stored as data types in Firestore; they are part of code logic, not data.
  3. Final Answer:

    Function -> Option B
  4. Quick Check:

    Functions are not data types in Firestore [OK]
Hint: Remember: Firestore stores data, not code like functions [OK]
Common Mistakes:
  • Confusing code functions with data types
  • Thinking all JavaScript types are supported
  • Assuming Firestore stores executable code
2. Which is the correct way to store a timestamp in Firebase Firestore?
easy
A. Store as a number representing milliseconds since epoch
B. Use a string with date format like '2024-06-01'
C. Use the Firebase Timestamp type
D. Use a boolean true or false

Solution

  1. Step 1: Understand Firestore timestamp storage

    Firestore has a special Timestamp type to store date and time accurately.
  2. Step 2: Compare options

    Strings and numbers can store dates but lack Firestore's timestamp features; booleans are unrelated.
  3. Final Answer:

    Use the Firebase Timestamp type -> Option C
  4. Quick Check:

    Timestamp type stores dates best [OK]
Hint: Use Firebase Timestamp for dates, not strings or numbers [OK]
Common Mistakes:
  • Storing dates as plain strings
  • Using numbers without Timestamp type
  • Confusing booleans with dates
3. What will be the data type of the field location after this Firestore document is saved?
const docData = { location: new firebase.firestore.GeoPoint(40.7128, -74.0060) };
medium
A. GeoPoint
B. Array
C. String
D. Map

Solution

  1. Step 1: Identify the data type used

    The code uses new firebase.firestore.GeoPoint() which creates a GeoPoint object.
  2. Step 2: Understand Firestore storage

    Firestore stores GeoPoint objects as GeoPoint type, representing geographic coordinates.
  3. Final Answer:

    GeoPoint -> Option A
  4. Quick Check:

    GeoPoint stores latitude and longitude [OK]
Hint: GeoPoint objects store coordinates, not strings or arrays [OK]
Common Mistakes:
  • Thinking GeoPoint is stored as string
  • Assuming coordinates are arrays
  • Confusing GeoPoint with map type
4. You try to save this data in Firestore:
{ name: 'Alice', age: '25' }

But you want age to be a number. What is the error and how to fix it?
medium
A. No error, Firestore converts string to number automatically
B. No error, but age should be stored as boolean true
C. Error: Firestore does not allow strings, use boolean instead
D. Error: age is string, fix by storing age as number 25

Solution

  1. Step 1: Check data types in the object

    Age is stored as a string '25', not a number 25.
  2. Step 2: Understand Firestore type strictness

    Firestore stores data as given; it does not convert string to number automatically.
  3. Final Answer:

    Error: age is string, fix by storing age as number 25 -> Option D
  4. Quick Check:

    Store numbers as numbers, not strings [OK]
Hint: Store numbers as numbers, not strings to avoid type errors [OK]
Common Mistakes:
  • Assuming Firestore auto-converts types
  • Using booleans for numbers
  • Ignoring type mismatch warnings
5. You want to store a user's profile with name, age, location (latitude and longitude), and signup date in Firestore. Which data types should you use for location and signupDate fields?
hard
A. location as GeoPoint, signupDate as Timestamp
B. location as Map with lat/lng numbers, signupDate as string
C. location as Array of numbers, signupDate as number (milliseconds)
D. location as string 'lat,lng', signupDate as boolean true

Solution

  1. Step 1: Identify best types for location and date

    Firestore provides GeoPoint for geographic coordinates and Timestamp for dates.
  2. Step 2: Evaluate options

    Using GeoPoint and Timestamp ensures correct storage, querying, and indexing.
  3. Final Answer:

    location as GeoPoint, signupDate as Timestamp -> Option A
  4. Quick Check:

    Use GeoPoint and Timestamp for location and dates [OK]
Hint: Use GeoPoint for locations and Timestamp for dates [OK]
Common Mistakes:
  • Storing dates as strings
  • Using arrays for location
  • Confusing booleans with dates
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard