This guide explains how to deploy Firestore indexes for the notifications feature. The app will work immediately with the simplified query, but deploying indexes will improve performance.
Good News! The app is already configured to work without waiting for index deployment.
The NotificationsScreen.tsx uses:
- Simple query:
orderBy('createdAt', 'desc')only - Client-side filtering: Filters active/expired notifications in the app
- Works immediately: No Firebase configuration needed
- Open the app
- Navigate to Notifications tab
- Notifications should load successfully
- No index errors!
For better performance with large datasets, deploy the Firestore indexes.
# Install Firebase CLI if not already installed
npm install -g firebase-tools
# Login to Firebase
firebase login
# Initialize Firebase (if not done)
firebase init firestore# From project root directory
cd /data/data/com.termux/files/home/Reshme_Info
# Deploy indexes
firebase deploy --only firestore:indexesExpected Output:
✔ Deploy complete!
Indexes deployed:
- notifications (isActive, createdAt)
- cocoonPrices (multiple indexes)
- dailySummaries (multiple indexes)
Index build status: https://console.firebase.google.com/firestore/indexes
Build Time: 2-10 minutes depending on existing data
- Go to Firebase Console
- Select your project: reshmeinfo
- Navigate to Firestore Database
- Click Indexes tab
Click Create Index and enter:
Collection: notifications
Fields to index:
1. isActive → Ascending
2. createdAt → Descending
Query scope: Collection
- Status will show "Building..."
- Wait 2-10 minutes for completion
- Refresh page to see "Enabled" status
Firebase provided this direct link in your error:
https://console.firebase.google.com/v1/r/project/reshmeinfo/firestore/indexes?create_composite=ClBwcm9qZWN0cy9yZXNobWVpbmZvL2RhdGFiYXNlcy8oZGVmYXVsdCkvY29sbGVjdGlvbkdyb3Vwcy9ub3RpZmljYXRpb25zL2luZGV4ZXMvXxABGgwKCGlzQWN0aXZlEAEaDQoJY3JlYXRlZEF0EAIaDAoIX19uYW1lX18QAg
Steps:
- Click the link above (or from your error message)
- Firebase Console opens with pre-filled index configuration
- Click "Create Index"
- Wait for build completion
Once the index is built (status shows "Enabled"), enable the optimized query:
Edit: screens/NotificationsScreen.tsx (lines 42-53)
Comment out the simple query:
// OPTION 1: Simple query (works without index - use this for immediate testing)
// const q = query(
// collection(db, COLLECTIONS.NOTIFICATIONS),
// orderBy('createdAt', 'desc')
// );Uncomment the optimized query:
// OPTION 2: After deploying indexes, uncomment this for better performance
const q = query(
collection(db, COLLECTIONS.NOTIFICATIONS),
where('isActive', '==', true),
orderBy('createdAt', 'desc')
);Remove client-side filtering (line 63):
// Before (with client-side filter)
if (data.isActive && (!expiresAt || expiresAt > new Date())) {
// After (index handles isActive)
if (!expiresAt || expiresAt > new Date()) {{
"collectionGroup": "notifications",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "isActive",
"order": "ASCENDING"
},
{
"fieldPath": "createdAt",
"order": "DESCENDING"
}
]
}- isActive: Filters only active notifications
- createdAt: Sorts by newest first
- Combined: Efficient query for notification feed
- Go to Firestore → Indexes
- Look for "notifications" collection
- Status should show "Enabled" (green)
// This query should work without errors
const q = query(
collection(db, COLLECTIONS.NOTIFICATIONS),
where('isActive', '==', true),
orderBy('createdAt', 'desc')
);Query: orderBy('createdAt', 'desc')
Filter: Client-side (JavaScript)
Documents read: All notifications
Performance: Good for <100 notifications
Query: where('isActive', true) + orderBy('createdAt', 'desc')
Filter: Server-side (Firestore)
Documents read: Only active notifications
Performance: Excellent for any size
- ✅ Faster query execution
- ✅ Reduced bandwidth (fewer documents)
- ✅ Lower Firestore read costs
- ✅ Better scalability
Problem: Index shows "Building..." for >15 minutes
Solutions:
- Refresh the Firebase Console page
- Check for existing data in
notificationscollection - Delete index and recreate
- Contact Firebase support if persistent
Problem: Still getting index error after deployment
Solutions:
- Verify index status is "Enabled" (not "Building")
- Check index fields match exactly:
isActive(Ascending)createdAt(Descending)
- Restart app / clear cache
- Check Firestore rules allow reads
Problem: Created index but still getting errors
Solution: Delete incorrect index and recreate:
- Firestore Console → Indexes
- Find notifications index
- Click delete (⋮ menu)
- Create correct index using this guide
- Index storage: Minimal cost (few KB per index)
- Read operations: Optimized query reduces reads
- Build time: One-time operation (free)
With 1000 notifications, 100 active:
Without index:
- Reads all 1000 documents
- Client filters to 100
- Cost: 1000 reads
With index:
- Reads only 100 active documents
- Server filters efficiently
- Cost: 100 reads
- Savings: 90%
- ✅ Deploy indexes before launching features
- ✅ Monitor index build completion
- ✅ Keep
firestore.indexes.jsonin version control - ✅ Document custom indexes in code comments
- ✅ Test queries in development first
- ✅ Use indexes for frequently-run queries
- ✅ Combine filters efficiently (indexed first)
- ✅ Avoid querying all documents when possible
- ✅ Use client-side filtering only as fallback
- Updated
firestore.indexes.json - Tested simplified query (works now)
- Documented index requirements
- Choose deployment method (CLI/Console/Link)
- Create notifications index
- Wait for "Enabled" status (2-10 min)
- Verify index in Firebase Console
- Switch to optimized query in code
- Test notifications load correctly
- Monitor performance improvements
- Remove client-side filtering (optional)
- Check Firebase status: status.firebase.google.com
- Firebase Support: firebase.google.com/support
- Community: Stack Overflow (firebase tag)
- App works immediately with simplified query
- No index required for testing
- Client-side filtering handles active/expired logic
- Deploy index for better performance
- Reduces Firestore reads by 90%
- Scales better with more notifications
None for testing! Deploy index later for production optimization.
Last Updated: October 30, 2025 Index Status: Not deployed (app works without it) Next Step: Test notifications, deploy index before production