Cloud Firestore is Google Firebase's NoSQL document database, built for apps that need data to sync live to every connected device. It holds around #13 in real-world database usage (roughly 5.7% share), and it's the default database for most new Firebase mobile and web apps thanks to its tight integration with Firebase auth, hosting, and cloud functions.
Firestore stores JSON-like documents in collections, and clients can subscribe to live updates instead of polling:
import { getFirestore, collection, addDoc, onSnapshot, query, where } from 'firebase/firestore'
const db = getFirestore();
// add a new document
await addDoc(collection(db, 'messages'), {
text: 'hello world',
createdAt: new Date()
});
// listen for live changes matching a query
const q = query(collection(db, 'messages'), where('read', '==', false));
onSnapshot(q, (snapshot) => {
snapshot.forEach(doc => console.log(doc.data()));
});
Firestore is enabled from the Firebase console on a new or existing project, then wired up with the Firebase SDK:
# install the Firebase SDK in your project
npm install firebase
# then initialize it with the config copied from the Firebase console