NoSQL Databases
Course: Advancing Database Topics I
Teacher: CUADROS QUIROGA, PATRICK JOSE
Firebase
Firebase is an application development platform created by Google that provides a wide range of cloud-based tools and services. Its main goal is to simplify developers' work by offering a robust and scalable infrastructure, reducing the need to manage servers and backend processes. This platform allows developers to create, manage, and improve mobile and web applications efficiently, leveraging its various services to address the primary needs of development.
Among its key components is Firebase Authentication, which provides a secure authentication system through methods like email, social networks, and anonymous authentication. It also offers real-time databases such as Firebase Realtime Database and Cloud Firestore, enabling efficient data synchronization between clients and handling more complex data structures, respectively. These databases are ideal for applications that require continuous collaboration or data synchronization.
Additionally, Firebase offers services like Cloud Storage for storing and sharing files in the cloud, and Cloud Functions, a serverless environment that allows you to run backend code in response to events within the platform. It also includes Firebase Hosting, which enables secure hosting of web content with support for SSL and custom domains, making it essential for progressive web applications (PWAs).
On the other hand, Firebase Cloud Messaging (FCM) facilitates direct communication with users through push notifications to mobile devices and web browsers. Firebase also provides advanced analytics tools with Firebase Analytics, which delivers detailed insights into user behavior, and Crashlytics, for monitoring and managing errors within the application. This helps identify and quickly resolve critical issues efficiently.
Another important aspect of Firebase is its ability to make predictions using machine learning through Firebase Predictions, which allows developers to foresee user behavior and act proactively. Additionally, the A/B Testing service enables experimentation to optimize the user experience and improve app performance by comparing different variants.
Firebase stands out for its integration with the Google ecosystem and for being a backend-as-a-service (BaaS) solution, allowing developers to focus more on application logic and less on infrastructure. Its scalability and security, managed by Google, along with extensive documentation and community support, make it a very popular option for both startups and large-scale companies looking to improve efficiency in app development and management. This platform is commonly used in real-time chat applications, e-commerce apps, mobile games, and progressive web applications, where data synchronization and direct communication with users are crucial.
Example
First, we create our project in Firebase

In cmd, we install the Firebase CLI client by command.

We enter our credentials

Once authentication is confirmed, the list of projects will appear in Firebase with our institutional email account.

Next, we use the command to install and activate the flutterfire_cli package globally in our Dart project.

Let's connect our Flutter project to Firebase

In our project are the Firebase account credentials.

The FirebaseService class manages the students collection in Firebase Firestore with CRUD operations.
The createStudent() method creates a student with information such as name, age, and contact. getStudentById() obtains the data of a student according to their ID, while updateStudent() allows you to update this information. deleteStudent() deletes a student from the database using their ID. Finally, getAllStudents() retrieves all stored students.
Each method handles errors and displays messages to indicate the results of operations. The class facilitates centralized management of student data.
import 'package:cloud_firestore/cloud_firestore.dart';
class FirebaseService {
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
Future<void> createStudent(
String name, int age, String email, String phone, String address) async {
try {
final docStudent = _firestore.collection('students').doc();
final studentId = docStudent.id;
await docStudent.set({
'studentId': studentId,
'name': name,
'age': age,
'email': email,
'phone': phone,
'address': address,
'enrolledCourses': [],
});
print('Estudiante creado con éxito');
} catch (e) {
print('Error al crear estudiante: $e');
}
}
Future<Map<String, dynamic>?> getStudentById(String studentId) async {
try {
DocumentSnapshot<Map<String, dynamic>> docSnapshot =
await _firestore.collection('students').doc(studentId).get();
if (docSnapshot.exists) {
return docSnapshot.data();
} else {
print('Estudiante no encontrado');
return null;
}
} catch (e) {
print('Error al obtener estudiante: $e');
return null;
}
}
Future<void> updateStudent(
String studentId, Map<String, dynamic> updatedData) async {
try {
await _firestore
.collection('students')
.doc(studentId)
.update(updatedData);
print('Estudiante actualizado con éxito');
} catch (e) {
print('Error al actualizar estudiante: $e');
}
}
Future<void> deleteStudent(String studentId) async {
try {
await _firestore.collection('students').doc(studentId).delete();
print('Estudiante eliminado con éxito');
} catch (e) {
print('Error al eliminar estudiante: $e');
}
}
Future<List<QueryDocumentSnapshot<Map<String, dynamic>>>>
getAllStudents() async {
try {
final querySnapshot = await _firestore.collection('students').get();
return querySnapshot.docs;
} catch (e) {
print('Error al obtener la lista de estudiantes: $e');
return [];
}
}
}
Here we can see the created collection.

And this is the structure of the project, with each dart file fulfilling its CRUD function

Conclusion
Firebase is an all-in-one and scalable application development platform that provides all the necessary tools to create, manage, and optimize both mobile and web applications. Its cloud-based architecture allows developers to focus on business logic without worrying about infrastructure, making it ideal for projects of any size, from startups to large corporations.
By offering a robust set of backend services (BaaS), Firebase enables developers to concentrate on the user experience and frontend development. With solutions like secure authentication, real-time databases, and the ability to send push notifications, Firebase simplifies the creation of user-centered applications.
The ability to synchronize data in real-time through Firebase Realtime Database and Cloud Firestore is a significant advantage for applications requiring constant updates or real-time interaction, such as chat, team collaboration, or online gaming. Additionally, the automatic scaling of infrastructure managed by Google ensures that applications can grow without additional technical concerns.
Github link:
https://github.com/24or341/CRUD-NoSQL
BIBLIOGRAPHY:
Mora, S. L. (2020, mayo 17). Firebase: qué es, para qué sirve, funcionalidades y ventajas. DIGITAL55. https://digital55.com/blog/que-es-firebase-funcionalidades-ventajas-conclusiones/
¿Qué es Firebase? ¿Qué ventajas ofrece en 2023 a nuestras apps? (s/f). Seidor.com. Recuperado el 25 de octubre de 2024, de https://www.seidor.com/es-es/blog/firebase-que-es
Muradas, Y. (2021, junio 22). Qué es Firebase: Conoce la plataforma de Google. Openwebinars.net. https://openwebinars.net/blog/que-es-firebase-de-google/