Implement Firestore CRUD operations
✓Works with OpenClaudeYou are a Google Cloud Firebase developer. The user wants to implement complete Create, Read, Update, and Delete (CRUD) operations for Firestore documents.
What to check first
- Verify Firebase project is initialized: check for
google-services.json(Android) orGoogleService-Info.plist(iOS), or confirmfirebase initran for web - Run
npm list firebaseto confirm Firebase SDK is installed (v9.0.0+ for modular SDK recommended) - Verify Firestore security rules allow read/write for your authentication context
Steps
- Initialize Firebase app using the modular SDK and get a Firestore reference with
initializeApp()andgetFirestore() - Create documents using
addDoc()(auto-generated ID) orsetDoc()(custom ID) with the collection reference - Read single documents with
getDoc()passing a document reference, or fetch collections withgetDocs()and query constraints - Update existing documents using
updateDoc()to modify specific fields, orsetDoc()withmerge: trueto avoid overwriting - Delete documents with
deleteDoc()passing a document reference - Handle Firestore timestamps using
serverTimestamp()for server-side consistency - Implement error handling with try-catch blocks for network and permission failures
- Use
onSnapshot()for real-time listeners instead of one-time reads when appropriate
Code
import { initializeApp } from 'firebase/app';
import {
getFirestore,
collection,
addDoc,
setDoc,
getDoc,
getDocs,
updateDoc,
deleteDoc,
doc,
serverTimestamp,
query,
where,
orderBy,
limit,
onSnapshot
} from 'firebase/firestore';
const firebaseConfig = {
apiKey: 'YOUR_API_KEY',
projectId: 'YOUR_PROJECT_ID',
databaseURL: 'YOUR_DB_URL'
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
// CREATE: Add new document with auto-generated ID
async function createUser(userData) {
try {
const docRef = await addDoc(collection(db, 'users'), {
...userData,
createdAt: serverTimestamp()
});
console.log('Document created with ID:', docRef.id);
return docRef.id;
} catch (error) {
console.error('Error creating document:', error);
}
}
// CREATE: Set document with custom ID
async function createUserWithId(userId, userData) {
try {
await setDoc(doc(db, 'users', userId), {
...userData,
createdAt: serverTimestamp()
});
console.log('Document set with ID:', userId);
} catch (error) {
console
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Cloud (AWS/GCP/Azure) Skills
Other Claude Code skills in the same category — free to download.
Lambda Function
Create AWS Lambda function with handler
S3 Operations
Set up S3 bucket operations (upload, download, presigned URLs)
DynamoDB CRUD
Create DynamoDB CRUD operations
SQS Setup
Set up SQS queue producer and consumer
SNS Notifications
Configure SNS for push notifications
CloudFront Setup
Set up CloudFront CDN distribution
Cognito Auth
Implement AWS Cognito authentication
RDS Setup
Configure RDS database connection
Want a Cloud (AWS/GCP/Azure) skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.