0
0
Firebasecloud~10 mins

Data modeling best practices in Firebase - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a Firestore document reference for a user with ID 'user123'.

Firebase
const userRef = firestore.collection('users').[1]('user123');
Drag options to blanks, or click blank then click option'
Aget
Bdoc
Cadd
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'doc' to reference a document.
2fill in blank
medium

Complete the code to add a new document with data to the 'orders' collection.

Firebase
firestore.collection('orders').[1]({ item: 'book', quantity: 1 });
Drag options to blanks, or click blank then click option'
Aset
Bdoc
Cadd
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'set' without a document reference.
3fill in blank
hard

Fix the error in the code to update the user's email in Firestore.

Firebase
firestore.collection('users').doc('user123').[1]({ email: 'new@example.com' });
Drag options to blanks, or click blank then click option'
Aupdate
Bset
Cget
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'set' which overwrites the entire document.
4fill in blank
hard

Fill both blanks to create a query that gets all orders where quantity is greater than 5.

Firebase
firestore.collection('orders').[1]('quantity', '[2]', 5).get();
Drag options to blanks, or click blank then click option'
Awhere
B>
C<
DorderBy
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'orderBy' instead of 'where' for filtering.
5fill in blank
hard

Fill all three blanks to create a map of user IDs to their email addresses for users with active status.

Firebase
const activeUsers = {};
firestore.collection('users').where('status', '==', 'active').get().then(snapshot => {
  snapshot.forEach(doc => {
    activeUsers[doc.[1]] = doc.data().[2];
  });
  console.log(activeUsers); // Maps [3] to emails
});
Drag options to blanks, or click blank then click option'
Aid
Bemail
Cuser IDs
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'status' instead of 'email' for the email field.