0
0
Firebasecloud~15 mins

In and not-in queries in Firebase - Mini Project: Build & Apply

Choose your learning style9 modes available
PMC: In and not-in queries
📖 Scenario: You are managing a small online store's inventory using Firebase Firestore. You want to learn how to query products based on categories they belong to or exclude certain categories.
🎯 Goal: Build Firestore queries that use in and not-in operators to filter products by their categories.
📋 What You'll Learn
Create a Firestore collection reference called productsRef pointing to 'products'
Create a list variable called categoriesToInclude with exact values ['electronics', 'books', 'clothing']
Write a Firestore query called includeQuery that finds products where the 'category' field is in categoriesToInclude
Write a Firestore query called excludeQuery that finds products where the 'category' field is not in categoriesToInclude
💡 Why This Matters
🌍 Real World
Filtering products by categories is a common task in online stores to show customers relevant items.
💼 Career
Knowing how to use Firestore queries with 'in' and 'not-in' operators is essential for building efficient and user-friendly cloud-based applications.
Progress0 / 4 steps
1
Create Firestore collection reference
Create a Firestore collection reference called productsRef that points to the 'products' collection using firebase.firestore().collection('products').
Firebase
Need a hint?

Use firebase.firestore().collection('products') to get the collection reference.

2
Create categories list
Create a constant array called categoriesToInclude with these exact string values: 'electronics', 'books', and 'clothing'.
Firebase
Need a hint?

Use square brackets [] to create the array with the exact values.

3
Write query using 'in' operator
Write a constant called includeQuery that queries productsRef using .where('category', 'in', categoriesToInclude) to find products whose category is in the list categoriesToInclude.
Firebase
Need a hint?

Use .where('category', 'in', categoriesToInclude) on productsRef.

4
Write query using 'not-in' operator
Write a constant called excludeQuery that queries productsRef using .where('category', 'not-in', categoriesToInclude) to find products whose category is not in the list categoriesToInclude.
Firebase
Need a hint?

Use .where('category', 'not-in', categoriesToInclude) on productsRef.