CRUD using Cloud Firestore
Learn how to execute CRUD operations using Cloud Firestore and React Native.
We'll cover the following...
CRUD (create, read, update, and delete) are the four basic
Create
As the name applies, the “create” operation in CRUD is used to create a new entry inside the database. To implement the “create” operation, we first have to import these functions from the @firebase/firestore library:
-
collection -
addDoc
import { collection, addDoc } from "@firebase/firestore";
Additionally, we also have to create a Firebase configuration file to connect our database with the React Native application. Note that this step is required for all the CRUD operations we discuss later in this lesson.
import { initializeApp } from 'firebase/app';import { initializeFirestore } from 'firebase/firestore';const firebaseConfig = {apiKey: "", // Your apiKey goes hereauthDomain: "", // Your authDomain goes hereprojectId: "", // Your projectId goes herestorageBucket: "", // Your storageBucket goes heremessagingSenderId: "", // Your messagingSenderId goes hereappId: "" // Your appId goes here};const app = initializeApp(firebaseConfig);const db = initializeFirestore(app, {experimentalForceLongPolling: true,});export { db };
Once the steps above have been completed, we can implement the “create” operation inside our application.
import { initializeApp } from 'firebase/app';
import { initializeFirestore } from 'firebase/firestore';
const firebaseConfig = {
apiKey: "", // Your apiKey goes here
authDomain: "", // Your authDomain goes here
projectId: "", // Your projectId goes here
storageBucket: "", // Your storageBucket goes here
messagingSenderId: "", // Your messagingSenderId goes here
appId: "" // Your appId goes here
};
const app = initializeApp(firebaseConfig);
const db = initializeFirestore(app, {
experimentalForceLongPolling: true,
});
export { db };In the code snippet above, we have implemented the “create” operation’s logic inside the create ...