Using Collection Group Queries in Firebase
📖 Scenario: You are building a simple app to track user comments on different posts. Each post has its own collection of comments stored in subcollections. You want to find all comments across all posts that contain a specific keyword.
🎯 Goal: Build a Firebase query that uses a collection group query to find all comments containing the word "great" in their text, regardless of which post they belong to.
📋 What You'll Learn
Create a Firestore collection called
posts with at least two documents.Each
posts document should have a subcollection called comments with comment documents.Create a variable called
keyword set to the string "great".Write a collection group query on
comments to find all comments where the text field contains the keyword.Store the query in a variable called
query.💡 Why This Matters
🌍 Real World
Collection group queries let you search across many subcollections with the same name, useful for apps with nested data like comments on posts or reviews on products.
💼 Career
Understanding collection group queries is important for building scalable, efficient Firestore apps that need to search data across multiple nested collections.
Progress0 / 4 steps