Posts

Showing posts with the label Cloud Firestore Structure

How to make Firebase query search not case sensitive #18

Image
How to make Firebase query search not case sensitive because you know Firebase provide exact match "==" with case sensitive. So we will solve this issue in the chapter in detail. We will use the Laravel PHP SDK for the firebase for all the queries stuff. Also we will see case insensitive sorting with Firebase orderBy using Firebase search ignoring case. Now lets consider a simple example, you have 'Student' list and you want to search by name. So the main use of any search is that, you insert one or two characters and the system should search the most matching one, but that not the case in Firebase. Firebase is a case sensitive. Means string "Name" and "name" are two different values for Firebase. All Firebase developers are facing this issue, which is most basic necessity. So lets first understand, currently what is provided by Firebase. See the below example of Student List. Now here you see, we have a Student ...

Chapter 12 - Delete data from Firebase using Laravel PHP

Image
In this chapter, we will learn how to delete the data from Firebase Cloud Firestore database collection using Laravel Framework PHP SDK. Now consider the following list of students in the 'Student' collection Suppose you want to delete the Student by document id '8suVf4FphzZLuTFJtdFe', you have to fire the below query. app('firebase.firestore')->database()->collection('Student')->document('8suVf4FphzZLuTFJtdFe')->delete(); This will delete the Student data from Student collection. Now if you have to delete the student having id = 3, then this can be done by the following query $students = app('firebase.firestore')->database()->collection('Student')->where('id','==',3)->limit(1)->documents(); $students ->rows()[0]->delete(); Now consider if you have to delete students having 'passoutyear' ...

Chapter 11 - Update data to Firebase using Laravel PHP

Image
In this chapter, we will learn how to update data to Firebase Cloud Firestore using Laravel PHP package. Consider the list of Student in Firebase Cloud Firestore. We would update these student data for all different type of datatypes of fields. Update normal string field name $student = app('firebase.firestore')->database()->collection('Student')->document(<studentid>); Example $student = app('firebase.firestore')->database()->collection('Student')->document('defT5uT7SDu9K5RFtIdl') ->update([ ['path' => 'name', 'value' => 'John Kone'] ]); After update, firebase will look like this Before updating or even inserting a value for fields like Integer or float, boolean make sure you convert your request params to specific datatype $student = app('...

How to auto increment a Cloud Firestore document existing number field id #9

Image
Learn How to auto increment a Cloud Firestore document existing number field id. In this chapter, we will learn how to insert a data with an auto increment id and using it an unique id instead of default Push ID provided by Firebase. Consider the following example: You have a Student collection and it has data with auto incremented value. When you insert the next, it should have id = 4. Now Firebase doesnot provide anything related to this autoincrement feature. It has only unique id generated by its logic. So we will do some manual coding for it. Now, you have the easy solution is to get the total size of the list of documents +1. Consider the following code $newid = app('firebase.firestore')->database()->collection('Student') ->documents()->size()+$i; //Insert new record app('firebase.firestore')->database()->collection('Student') ->document($ne...

Chapter 2 - MySQL structure comparison with Firebase structure

Image
In this chapter, we will discuss how you can decide the structure of your data in Firebase as compared to you do it in MySQL. So lets begin. Consider a simple example of two tables "students" and "courses" and a relationship table which stores the info of student applying the specific courses as student_course. Following is the student table with the basic fields firstname, lastname etc. The second is the courses table with the basic fields name, duration, cost etc. The third one is the Student_Course as relationship table to store the data of student applying to which course. Now your normal query in MySQL to fetch a particular course with the applied student would be this. select c.name as course, s.firstname as student from courses as c left join student_course as sc on sc.course_id = c.id left join students as s on s.id = sc.student_id where c.id = 1 For Laravel lovers (assuming you know the Eloquent ORM. Don't know? co...