addDoc() adds a new document to a collection with an auto-generated ID. You pass a CollectionRef (from collection(db, "name")) and a plain JavaScript object — Firestore stores it as a document.
Each document lives at a path like users/{autoId}. The returned reference contains the generated id so you can refer to the document later.
- `addDoc()` auto-generates a unique document ID
- The first argument is a CollectionRef, not a string path
- The returned ref gives you the generated ID immediately
Firebase Playground — Learn Firestore in Your Browser with a Full Simulator
What's included
Features
About this tool
Learn Firebase Firestore Without a Firebase Account — Run Real Firestore Operations Instantly in Your Browser
Firebase Firestore is the most widely-used NoSQL document database for web and mobile apps. It powers real-time features in millions of applications — yet learning it traditionally requires creating a Firebase project, enabling Firestore in the console, configuring security rules, and wiring up SDK credentials before writing a single document. This playground removes every barrier so you can focus entirely on understanding how Firestore works.
All Firestore operations run entirely in your browser — no data is sent to Firebase servers. Open any lesson and the code is already there. Click Run and the simulator executes against an in-memory Firestore engine built in JavaScript. Every addDoc(), setDoc(), getDoc(), query(), and onSnapshot() call works exactly as it does in the real Firebase SDK — and the live document tree on the right shows the resulting Firestore state after every run.
How the document tree works: After clicking Run, the Firestore State panel on the right renders a collapsible tree of all collections, documents, and fields in the in-memory store. Collection nodes show in Firebase orange with a document count badge. Each document expands to show its fields with values colour-coded by type — strings in green, numbers in amber, booleans in purple, arrays as comma-separated lists. Subcollections appear nested under their parent document. This visual makes the Firestore data model immediately clear: collections contain documents, documents contain fields, and subcollections live inside documents.
The 23-lesson curriculum spans 11 chapters and takes you from your first document to production patterns. Getting Started introduces addDoc() — which auto-generates a unique document ID — and setDoc(), which writes to a path you specify. Understanding the difference between these two is the first fundamental Firestore concept.
Reading Data covers getDoc() for single document reads with the DocumentSnapshot pattern (always call .exists() before .data()) and getDocs() for fetching all documents in a collection as a QuerySnapshot with .docs, .size, .empty, and .forEach().
Updating & Deleting teaches updateDoc() for partial field updates without touching other fields — critical for safe multi-client writes — and deleteDoc() for document removal, including the important caveat that subcollections are not automatically deleted.
Querying introduces the functional query composition pattern: query(collectionRef, ...constraints) builds a query descriptor, then getDocs() executes it. The where(field, op, value) constraint supports all Firestore operators — ==, !=, <, <=, >, >=, in, not-in, and array-contains. orderBy(field, direction) sorts results, and limit(n) caps the number returned. Constraints combine in a single query() call.
Special Values covers the three atomic sentinel values that make Firestore safe for concurrent updates: serverTimestamp() writes the server's actual time instead of the client clock; increment(n) atomically adjusts a numeric field without a read-modify-write race; arrayUnion() and arrayRemove() add or remove array items without duplicates and without reading the full array first.
Advanced lessons cover onSnapshot() for real-time listeners — which fire immediately with the current state and then on every subsequent change — and subcollections using collection(docRef, "name") for one-to-many relationships like posts and their comments.
Then the curriculum moves into production territory. Pagination & Aggregation teaches cursor pagination with orderBy() + startAfter() + limit() (Firestore paginates with cursors, never offsets) and counting documents efficiently with getCountFromServer(). Transactions & Batches covers atomic writeBatch() (all-or-nothing writes for things like money transfers) and runTransaction() (safe read-then-write for counters and inventory, with automatic retries). Data Modeling teaches the NoSQL mindset — denormalizing hot fields to avoid extra reads since Firestore has no JOINs, and choosing between an array field and a subcollection for one-to-many data.
Authentication covers the full email/password flow with createUserWithEmailAndPassword(), signInWithEmailAndPassword(), signOut(), and reacting to onAuthStateChanged() to guard protected pages. Finally, Security Rules shows the real firestore.rules syntax for ownership checks and data validation, modeled in runnable JavaScript so you can test the access decisions — because client SDK calls are only as safe as the rules running on Google's servers.
Why Use Firebase?
Firebase is a backend-as-a-service that lets you ship a complete app without managing servers. Firestore gives you a real-time NoSQL database that syncs across every connected client automatically; Authentication handles sign-up, sign-in, and sessions out of the box; Security Rules enforce access control server-side; and the whole platform scales automatically with a generous free tier, plus hosting and cloud functions when you need them. That combination lets a solo developer or small team launch a production-grade app remarkably fast — which is why Firebase powers millions of web and mobile apps. This playground teaches both the everyday Firestore API and the professional concerns (transactions, pagination, auth, rules) that separate a prototype from a production app. It pairs naturally with the MongoDB Playground for comparing NoSQL models and the JavaScript Playground for the async/await fundamentals every Firebase call relies on.
Step by step
How to Use
- 1Choose a lesson from the sidebarThe left sidebar lists all 23 lessons organised into 11 chapters. Start at "Add your first document" if you are new to Firestore, or jump to a pro chapter — Transactions & Batches, Authentication, or Security Rules — that matches your level. Your last active lesson is remembered when you return.
- 2Read the concept explanationA collapsible panel above the code explains the Firestore concept for that lesson. It describes what the API does, when to use it, and how it relates to real Firestore behaviour. Inline
codemarkers highlight method names, and bold text flags key distinctions like the difference between addDoc and setDoc. - 3Click Run to execute the codeThe lesson code is shown in a read-only panel so you can focus on understanding each example. Click the orange Run button or press Ctrl+Enter to execute it against the in-memory Firestore simulator. The code runs asynchronously — all await calls resolve as they would in a real Firestore app.
- 4Read the console outputThe Console Output panel below the code shows each console.log line numbered in sequence. Values are stringified — objects display as formatted JSON, arrays as comma-separated, primitives as plain text. If the code throws an error, it appears in red with the error message.
- 5Inspect the Firestore State treeThe Firestore State panel on the right renders a live visual tree of all documents created during the run. Collections appear in orange with a document count. Click any collection or document to expand or collapse it. Fields show their values colour-coded by type — this tree makes the Firestore data model tangible and is one of the most effective ways to understand how data is organised.
Real-world uses
Common Use Cases
Got questions?
Frequently Asked Questions
No. Everything runs in your browser against an in-memory JavaScript simulator. No Firebase account, API key, or project is needed. All Firestore operations run entirely in your browser — no data is sent to Firebase servers.
Beginner to pro across 23 lessons: addDoc, setDoc (with merge), getDoc, getDocs, updateDoc, deleteDoc, query with where/orderBy/limit, onSnapshot listeners, serverTimestamp, increment, arrayUnion/arrayRemove, subcollections, cursor pagination with startAfter, getCountFromServer aggregation, batched writes (writeBatch), transactions (runTransaction), data modeling, Firebase Authentication, and security rules.
Firebase is a backend-as-a-service: a real-time Firestore database that syncs across clients, Authentication out of the box, server-side Security Rules, and automatic scaling on a generous free tier — so small teams ship production apps without managing servers. The playground teaches both the everyday API and production concerns like transactions, pagination, auth, and rules.
A batch (writeBatch) groups up to 500 writes that commit atomically but does not read. A transaction (runTransaction) reads first, then writes based on the read, retrying if the data changed. Use a batch for consistent related writes (a money transfer); use a transaction when the new value depends on the current one (a counter or inventory). Both are runnable lessons.
Yes — completely free, no account, no sign-up, no limits. All 23 lessons are available immediately.
After you click Run, the Firestore State panel on the right renders all collections, documents, and fields in the in-memory store. Collections show as orange folder nodes with a count badge, documents show their ID and fields colour-coded by type, and subcollections appear nested under their parent document.
addDoc() auto-generates a unique random ID. setDoc() writes to a path you specify using doc(db, "col", "your-id"). setDoc() overwrites the document by default; pass { merge: true } to only update supplied fields. Use addDoc() when the ID does not matter, setDoc() when it does.
serverTimestamp() is replaced by the server's actual time on write. increment(n) atomically adjusts a number field — safe for counters with concurrent clients. arrayUnion() adds items without duplicates. arrayRemove() removes items. All are atomic and safe for concurrent writes.
Build a query with query(colRef, ...constraints) — constraints are where(), orderBy(), and limit(). Then pass the query to getDocs() to execute it. The simulator supports all Firestore where operators: ==, !=, <, <=, >, >=, in, not-in, and array-contains.
The simulator covers the core API accurately. Differences: operations complete synchronously in memory (no network), onSnapshot fires once rather than subscribing to ongoing changes, compound queries need no composite indexes, transactions do not truly retry under contention, and security rules are taught as runnable JS models rather than enforced on a server. Ideal for learning the API and patterns before connecting to a real Firebase project.