MongoDB + Spring Boot 3 | Crash Course
Vložit
- čas přidán 5. 08. 2024
- Buy me a coffee: ko-fi.com/boualiali #spring #learning #springboot #springtutorial #springsecurity #developpement #java #arraylist #linkedlist #springdatajpa #querybuilder #aliboucoding #alibou #validation #mongodb #springboot_3
In this crash course, you will learn how to build high-performance web applications using Spring Boot 3.0 and MongoDB.
We'll start by discussing the key concepts of Spring Boot, including the basics of dependency injection, configuration, and testing.
Then, we'll dive into MongoDB and explore its powerful features for data modeling, querying, and indexing.
Along the way, we'll also cover best practices for optimizing the performance of your Spring Boot and MongoDB applications.
By the end of this course, you will have a solid understanding of how to use these technologies together to create powerful, scalable, and maintainable web applications.
Don't Forget to
===========================================
💯 Free courses here: aliboucoding.com
💯 Subscribe to the youtube channel
💯 Join our Discord Community - / discord
💯 Join our Facebook Group - / 589612651142975
💯 Join our Instagram: / alibou_coding
Table of content
00:00 Intro
02:01 What is mongoDB
03:54 The difference between SQL and NoSQL databases
06:28 How to choose between SQL and NoSQL databases
10:15 MongoDB UI tools
11:25 Why using docker for development
12:54 Create an empty docker compose file
14:25 Mongo server (docker compose)
18:46 Mongo express (docker compose)
21:42 Run docker compose and test
25:07 Collections and documents
28:14 Create a new spring project
31:56 Project structure
34:08 Include docker compose file into the project
37:38 Project architecture
41:10 Connect to MongoDB
44:34 Create a new database
45:57 Explain ADMIN, CONFIG and LOCAL databases
50:46 Create Java class
54:23 Transform the Java class to a collection
56:47 Create the mongo repository
59:01 Insert the first data into collection
01:04:48 Create the product service
01:06:48 Save the product
01:11:36 Find product by ID
01:12:25 Find all products
01:12:45 Delete products
01:13:13 CRUD - Create product controller
01:15:14 CRUD - Save product
01:16:51 CRUD - Find all products
01:17:48 CRUD - Find by ID
01:19:16 CRUD - Delete product
01:20:50 CRUD - Test operations
01:27:06 Extend the product model
01:29:47 Create Category java class
01:31:33 Use category as a field
01:34:09 Relationship between Product and category
01:35:16 Transform Category to a collection
01:36:11 Create a category repository
01:36:57 Insert categories at startup
01:38:51 The issue in linking collections
01:42:08 Add relation between collections
01:45:47 Add OpenApi dependency
01:47:33 Test and play with swagger UI
01:53:40 Continue learning
Table of content
00:00 Intro
02:01 What is mongoDB
03:54 The difference between SQL and NoSQL databases
06:28 How to choose between SQL and NoSQL databases
10:15 MongoDB UI tools
11:25 Why using docker for development
12:54 Create an empty docker compose file
14:25 Mongo server (docker compose)
18:46 Mongo express (docker compose)
21:42 Run docker compose and test
25:07 Collections and documents
28:14 Create a new spring project
31:56 Project structure
34:08 Include docker compose file into the project
37:38 Project architecture
41:10 Connect to MongoDB
44:34 Create a new database
45:57 Explain ADMIN, CONFIG and LOCAL databases
50:46 Create Java class
54:23 Transform the Java class to a collection
56:47 Create the mongo repository
59:01 Insert the first data into collection
01:04:48 Create the product service
01:06:48 Save the product
01:11:36 Find product by ID
01:12:25 Find all products
01:12:45 Delete products
01:13:13 CRUD - Create product controller
01:15:14 CRUD - Save product
01:16:51 CRUD - Find all products
01:17:48 CRUD - Find by ID
01:19:16 CRUD - Delete product
01:20:50 CRUD - Test operations
01:27:06 Extend the product model
01:29:47 Create Category java class
01:31:33 Use category as a field
01:34:09 Relationship between Product and category
01:35:16 Transform Category to a collection
01:36:11 Create a category repository
01:36:57 Insert categories at startup
01:38:51 The issue in linking collections
01:42:08 Add relation between collections
01:45:47 Add OpenApi dependency
01:47:33 Test and play with swagger UI
01:53:40 Continue learning
I've watched a lot of mongo db tutorials in English and Russian. I believe it is the best one for mongo db beginners
Wow, thank you!
Thank you very much for this video!
You're very welcome!
thank you so much, you are the best
Once again the content of your video allows me to move forward in my learning about the spring boot framework, in one of your videos you talked about database migrations and I then went deeper into the subject but it was with relational databases and here I'd like to know if it's possible to migrate non-relational databases, thank you Mr Ali.
Great job thanks a lot ye ghali ❤ ! The best 🥇🔝🔝
My pleasure 😊
Thx a lot Ali
My pleasure
Thank you @BoualiAli I always watch your tutorial
and they are really helpful
Glad you liked it!
Good video, but it seems to me that @DbRef annotation doesn't solve the problem u've described in section 'The issue in linking collections' 1:39:00. As I've noticed this annotation doesn't let u create a document with a child which doesn't have an id, but it still let u create a child which has a fake id.
Thank you very much
Welcome
Thank you
You're welcome
good tutorial
Happy you like it
Hi, from Morocco, I hope you are doing great.
I am about to create a chat app using Spring boot and MongoDB, I want to explore MongoDB's Tailable option, my app will also have desktop notifications.
By the way, your spring security tutorial is very interesting
Thank you for your feedback.
Hey Ali , thank you for this great resource , have you ever worked with elasticsearch api ? Do we need to follow the same approach in this video?
I never worked with it, so I can’t tell if it is the same approach or not
How to store this configuration for real production spring boot ? I don't think I want to put my username and password in application.yml which will be git-ed.
Bouali it's request, good to have all your contents in English which we all will get reached to it.
This is the plan. I'm doing all the new videos in english
Hello Sir , I am a college student from India ... Hope you are well ... I am working an andorid(JAVA) project like whatsapp which has feature of private chatting I unable to find the great resources could you please make a video in short how to do this...please sir
Thank you Ali for this tuto. Tell me, wictch theme do you use ? I like you intelliJ interface.
The new ui from the latest version of intellij
@@BoualiAli ok thanks
I will be using the IntelliJ plugin for Mongo, Do I still need to create the container for mongo-express or I can skip that?
you can skip that
MongoExpress doesn't update the list of collections in the database so I don't see Product, whereas if I connect with MongoDB Compass I see both the collection and the data
At first glance, I thought it was an issue. However, after two days of thorough investigation, I realized the importance of deleting all MongoDB-related data on the localhost. This step was crucial even after reinstalling Docker and MongoDB Community Edition. It was only after creating a new user and database that I finally saw the solution.
can you please create one session for MongoDB usage with spring boot data mongo for file upload and best practice for file upload if we are not using aws s3 in that case and also how to write custom implementation for mongodb in spring boot 3 or anything so that we can aware of that.
I already implemented file upload in my previous video. check it
Getting an error at 1:03:20 , it says that it failed to execute CommandLineRunner , Exception executing Mongo credentials, Authentication failed on server
You have bad credentials to acces your mongo
@@BoualiAli how to solve this issue?
@@NomadicAlfa set the correct credentials
Dear friend, I ran into a similar problem and found a solution, All because you create your database before launching the application and because your data for authentication is not there, you have two solutions just delete the database and then it will work in the compilation process, or use this code in the database console:
use myDB
db.createUser(
{
user: "username",
pwd: "password",
roles: [ { role: "readWrite", db: "myDB" } ]
}
)
Darija plzzzzz ola arabic
Sorry bro
Most of my followers speak english
Failed to execute CommandLineRunner Caused by: org.springframework.data.mongodb.UncategorizedMongoDbException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='helaoui', source='admin', password=, mechanismProperties=}; nested exception is com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='helaoui', source='admin', password=, mechanismProperties=}
would you like to help me to fix the issue ?
in which part?
@@BoualiAli at time 1:06:48, save the product part
this is what i wrote in docker-compose.yml:
services:
mongodb:
image: mongo
container_name: mongo_db
ports:
- 27017:27017
volumes:
- mongo:/data
environment:
- MONGO_INITDB_ROOT_USERNAME=helaoui
- MONGO_INITDB_ROOT_PASSWORD=helaoui
mongo-express:
image: mongo-express
container_name: mongo_express
ports:
- 8081:8081
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=helaoui
- ME_CONFIG_MONGODB_ADMINPASSWORD=helaoui
- ME_CONFIG_MONGODB_SERVER=mongodb
volumes:
mongo: {}
and this what i wrote in application.yml:
spring:
data:
mongodb:
username: helaoui
password: helaoui
host: localhost
port: 27017
database: helaouicoding
when i omit the two lines from application.yml
username: helaoui
password: helaoui
it works fine but i can't see the changes in mongo express
@@abderrahmenhelaoui6511 there is a line missing.
Check the source code on my github and you will figure it out