0
0
Firebasecloud~10 mins

Subcollections 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 get a reference to a subcollection named 'orders' inside a document.

Firebase
const ordersRef = firestore.collection('users').doc('user123').[1]('orders');
Drag options to blanks, or click blank then click option'
Aadd
Bdoc
Ccollection
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using doc() instead of collection() to access a subcollection
Trying to use get() or add() directly to get a reference
2fill in blank
medium

Complete the code to add a new document to the 'orders' subcollection.

Firebase
firestore.collection('users').doc('user123').collection('orders').[1]({ item: 'book', quantity: 1 });
Drag options to blanks, or click blank then click option'
Aset
Bget
Cupdate
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using set() without a document reference
Using get() which only reads data
3fill in blank
hard

Fix the error in the code to correctly get a document from a subcollection.

Firebase
const orderDoc = firestore.collection('users').[1]('user123').collection('orders').doc('order456');
Drag options to blanks, or click blank then click option'
Aadd
Bdoc
Ccollection
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using collection() instead of doc() to get a document
Using get() which fetches data, not references
4fill in blank
hard

Fill both blanks to query all documents in the 'comments' subcollection of a post.

Firebase
const commentsQuery = firestore.collection('posts').doc('post789').[1]('comments').[2]();
Drag options to blanks, or click blank then click option'
Acollection
Bdoc
Cget
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using doc() instead of collection() to access subcollection
Forgetting to call get() to fetch documents
5fill in blank
hard

Fill all three blanks to update a field in a document inside a subcollection.

Firebase
firestore.collection('[1]').doc('[2]').collection('[3]').doc('doc001').update({ status: 'completed' });
Drag options to blanks, or click blank then click option'
Aprojects
Bproj123
Ctasks
Dusers
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up collection and document names
Using wrong collection names for subcollections