Это видео недоступно.
Сожалеем об этом.
Step-by-Step Tutorial: How to Integrate MongoDB in Your Spring Boot Application
HTML-код
- Опубликовано: 17 авг 2024
- 🟡 Get 1 to 1 coaching with me: topmate.io/eng...
🟡 Donate: paypal.me/engi...
🟡 Perks: www.youtube.co...
🔴 Instagram: / thevipulvats
🔴 GitHub: github.com/the...
🔴 Twitter: / thevipulvats
🔴 LeetCode: leetcode.com/t...
🔴 LinkedIn: / thevipulvats
🔴 Discord: / discord
🟢 Source code: github.com/cho...
Here is a concise guide on how to integrate MongoDB in a Spring Boot application in 10 steps:
Step 1: Set Up Your Spring Boot Project:
Create a new Spring Boot project using your preferred IDE or by using Spring Initializr. Include the necessary dependencies, including the MongoDB driver.
Step 2: Define a MongoDB Configuration:
Create a configuration class with the necessary configurations for connecting to MongoDB, including the host, port, and database name.
Step 3: Define a MongoDB Entity:
Create a POJO (Plain Old Java Object) class to represent your data model. Annotate this class with the necessary MongoDB annotations to define the collection name and field mappings.
Step 4: Create a Repository Interface:
Define a repository interface that extends the appropriate MongoDB repository interface. This interface will handle the CRUD (Create, Read, Update, Delete) operations for your MongoDB entity.
Step 5: Implement Service Layer:
Create a service class to handle business logic and interact with the MongoDB repository. Define methods for data manipulation and retrieval.
Step 6: Implement Data Initialization (Optional):
If required, initialize data in the database during application startup using data initialization scripts or methods.
Step 7: Implement Controller for REST API:
Create a controller class to define REST endpoints for interacting with the MongoDB data. Implement methods for handling HTTP requests, utilizing the service layer.
Step 8: Test Endpoints:
Test the REST API endpoints using tools like Postman or any other HTTP client to ensure the proper functioning of the MongoDB integration.
Step 9: Run and Test the Application:
Run the Spring Boot application and verify the integration by performing CRUD operations through the defined REST API endpoints.
Step 10: Handle Exception and Error Scenarios:
Implement error handling mechanisms to gracefully manage exceptions and errors that might occur during MongoDB integration. Implement proper logging and error response handling.
00:00 Introduction
01:06 Configuration
04:12 Best Practices
05:31 Repository
07:22 MongoRepository
09:10 @Document
09:51 @Id
11:39 Saving entity in db
18:10 Getting entity from db
22:36 Deleting entity from db
23:07 Updating entity in db
Instead of web series, i’m using RUclips for learning now. Your channel is So underrated. Went through all the lectures including mongodb, spring, system design, javascript, Java 8 (touch-notch) and Now following your Springboot and Linux course. You are full version of engineering college to me. Thank you so much. And also following your leetcode questions series too. If i get a job, i’ll give the credit most of it.
Also, Please start Frontend Framework course too. Like react or angular
Should start first javascript in brief then angular
The way you have explained the concept & implementation, its flawless. Thanks a lot to you for creating contents.
Thanks a lot for this this informative video, helped a lot!!
Hello Everyone,
Just for clarification why there is no @Component on the interface class:
Example: public interface SortAlog(); public class BubbleSortAlgo();
1. Interfaces and Beans:
- An interface defines a contract for a class to implement certain methods.
- A bean is a Spring-managed component that can be injected into other parts of your application.
2. @Autowired:
- This annotation allows Spring to automatically inject dependencies (i.e., create and manage objects) for you.
- When you use `@Autowired`, Spring looks for a bean of the required type and injects it.
3. Dynamic Binding:
- When you use an interface, the actual implementation is determined at runtime.
- Spring dynamically binds the interface to the appropriate implementation.
4. @Component:
- This annotation marks a class as a Spring component (i.e., a bean).
- In your example, `BubbleSortAlgo` is annotated with `@Component`, making it a candidate for injection.
So, in summary, `@Autowired` handles dependency injection, and `@Component` marks classes as beans. The interface allows dynamic binding to the correct implementation.
Thanks.
Bro it’s showing create a bean of the interface how to solve the issue
Copy the error paste it on stack overflow.
Much easier and better way to do R&D and solutions bhi mil jate majority error code ke
God Level Explanation and This guy deserves popularity
Awesome work your content is great. The way you engage it makes it more fun to learn. Please keep up the great work thank you so much for all your efforts. On a very light note- 🙂your tone often starts sounding like Anubhav Singh Bassi 🙂which makes it all the more fun to learn
Debug process was new to me. Thanks for walkthrough.
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
thank you sir for this amazing course. ❤
I was getting errors after externally adding dependency of mongodb , so I suggest to add that dependency while creating project using spring initializer itself name as Spring Data MongoDB
Hi bro, I am also facing errors with mongodb dependencies. Not able to scan mongorepository. how did you fixed it?
Your teaching skill is outstanding ...
I am fully new in java field but your video is too good 😊. Way of learning great .
Parallel other DB reference bhi lete raho sir for example few annotations which we use in JPA are different in mongo DB . Jo jpa use kare hai unke liye refer karna easy hoga but new jo honge unhe thoda problem hoga initially grasp karne mai . Just a feedback . Rest great work keep on doing it.
tagda lage raho munna bhai, the language you used that' s the connection between you and us.
Thank you so much, Sir. great work. every video worth of million views
It's just amazing, explanation is soo good. Keep uploading...
Thank you brother, it will be a huge help if you can share this course on LinkedIn.
Sir getAll() nhi chlrha sahi mongosh mein find() pr kuch nhi arha jabke post horha ha or postman pr bhi b=get nhi chlrha
One Thing i want to add i thought spring learning will be difficult but its easy Thanks @ED
marvelous concept
Sir my getAll()
Deletebyid()
update()
not working
and not able to debug can you help;
@Document(collation="company") insted of this use
@Document(collection = "journal_entries") small diffrance
Why does postman shows date and time as id while the db shows an actual auto generated id?
Eagerly waiting for the upcoming videos
Loved the content. I am waiting for the React series with Javascript even if it comes as a paid course. !!!!!
Get call showing internal error in postman and code return perfectly how can i resolve it ?
how you resolved it?
Sirji Love your videos! Please error handling and uske best practices bhi cover karna!
Mast lagg rahe hai ab takk videos
Bahut Badhiya, sab kuch bina bakwas ke!!!
the explanation is soo perfect and easy
How to debug was the cherry on top!
bro my getAll()
Deletebyid()
update()
not working
and not able to debug can you help;
@@tanujverma1126 Sure! give some details
@@tanujverma1126 sure bro, give some details
Please upload next series
I am waiting for your next series
Everything is good. Please pick some performance related topics like threads management, tomcat related stuff, api time outs, inspection of stack stace, max body length of payload for spring boot, actuators,
very beautifully explained
Thank you so much 🙂
best series on youtube
Thanks a lot! Please share this playlist on LinkedIn. It will be a huge support.
Great explanation sir, thanks a lot
I have a doubt :
id is coming out as an object of type : {date,timeStamp} for eg:
{
"id": {
"timestamp": 1714609873,
"date": "2024-05-02T00:31:13.000+00:00"
},
"title": "Night",
"content": "Im Sleeping",
"date": "2024-05-02T06:01:13.819"
},
if we are using this in our project this might not work. How to make it return ObjectId as String or some other compatible dataType. ?
Best Tutorial Ever, Thank you bhai
Most welcome
so amazing playlist sir
Great Explanation
I am unable to call the methods which I wrote inside the service rather I am able to call the methods directly which are present in MONGOREPOSITORY CLASS ANY CLUE WHATS WRONG THERE
Can we use @Service annotation instead of @Component for creating the bean in the service class? Btw teaching skills are outstanding.
Nice tutorials. Please create advance tutorials on spring boot
make series on microservices
Hello Vipul, I am glad to follow your videos. All of them has amazing contents. Though I have a query, while returning object from save method, I do not get Object ID (Timestamp and Date) field in my response in postman. It there anything I am missing?
I have just 1 doubt , why did we not use @Repository annotation in repo class and @Service in service class ?
We have @Component and all other annotations like @Controller @Service and @Repository are stereo typed annotations they all works the same
And you are right we have to use specific annotations for the perticular class (may be sir forget) for the convention
Fab❤
Awesome, great content
Very nice tutorial
thanks for this tutorial easily understandable . debug cocept is new for me great sir 😎😎
sir aapne mongoTemplate kyu nhi use kiye...?
agr ho skte to MongoTemplate pe video bna dijiye
killed it
findAll function not working
Can anyone help me
It works, the problem is we should not be using the collation attribute in the entity.
Instead write @Document(value = "journal_entries")
After debugging and checking I have this issue due to the spelling @Document("company") you can omit everything after @Document Monogo itself take it from DB :) now it works
Nice Voice Sir. I know everything but I am a fresher Sir can you help me for complete my fresher teg 😊😅
I am unable to call the methods which I wrote inside the service rather I can call the methods directly which are present in MONGOREPOSITORY
It sounds like there might be an issue with how the service methods are being called or possibly an issue with dependency injection. Ensure that your service is properly annotated with @Service and that it's being injected correctly where you're trying to use it. Also, double-check that the methods in the service are public and that you're calling them on an instance of the service, not directly on the repository. If you can provide some code snippets, I can help debug further!
Excellent.
Doesn't the db thread block the thread? Awesome video btw
can anyone explain why it is happen
Sir mere get call work nhi kr rhe error show ho rha plz help
Nice video
Is there a github link to these code lessons?
Sir I am facing an issue regarding the connection to database is there a way you can help me out?
I'm facing the same problem
Do you have solution for this
It was an amazing video but....i was not able to remember all. How will i build a project on my own?
although i understood how things are working
Spring boot ka sara code sahi likha h lakin api hit ni error 404 ara h kyo ?
Bhai Sahi Ho gaya kya PLease bhai bata do kese thik kiya
@@chaitanyakashyap9520 bhai ek baar postman ko refresh karo fir get ki api hit karo
@@chaitanyakashyap9520 aur code check karo apna shyd koi problem ho
@@chaitanyakashyap9520 ha hogaya mera sahi
MongoRepository class are not inherited why ? And @Document @Id shows error
Same issue
Same issue
In this video we can say this is crud operation?
Yes
@@EngineeringDigestin service class by you use @component rather than using @service.
25:21
hello Sir Me Jab Data Get Karta hu Tab Data Get Nahi Ho Pa Raha hey Put To ho Raha He pr Get Nahi Ho Raha
{
"status": 500,
"error": "Internal Server Error",
"path": "/DataSend"
}
Ye Error Aa Raha Hey PostMan Mey
bro update ur code with
@Putmapping("id/{myId}") and where ever sir placed id replace it with myId .
@@AnshulyouT Bhai merko same issue getAll waali api m aa raha hai
@@AnshulyouT BRo please copy and paste that Code Part
please
@@chaitanyakashyap9520 which part bro ?
@@AnshulyouT jahan jahan Change kiya hai code ko usse copy kar ke de do bhai Please help ho jayegi
Great explanation but one thing how will I remember all this? This topic is quite vast.
Not supposed to be remembered
it is showing error in mongorepositry
after updating pom.xml, right click --> maven --> reload project
eclipse m p banao backend and frontend connect kr bake
Lovely
{
"timestamp": "2024-06-19T12:20:00.947+00:00",
"status": 500,
"error": "Internal Server Error",
"path": "/journal"
}
please help anyone .........
have you solve the error?
@@shrutiraval6806 both of you guys look for the statement @Putmapping("id/{myId"}). here viper sir updated the variable myId with id so update id as myId everywhere or update with id everywhere . thank me later 😃
I’m getting server error (500) for get http but it is working for getbyid
Have you solve this error? i am also getting this error
@@shrutiraval6806 yes
@@shrutiraval6806 I think you can try @Document only instead of @Document(what ever you write)
Local date time throw error
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:3.1.2:deploy (default-deploy) on project journalApp: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::url parameter -> [Help 1]
Check application.propeties file is correct or not
Content is good ❤ but Why you use mongodb instead of mysql
because..
🌟🌟🌟🌟🌟
13:47
findAll function not working
After debugging and checking I have this issue due to the spelling @Document("company") you can omit everything after @Document Monogo itself take it from DB :) now it works
MySQL se kese kare 🥺
Muze samjane mein taklif ho rahi hai.. Help me sir..
Badam khao
Can it be like in put mapping
@PutMapping("id/{id}")
public JournalEntry upadteJournalEntry(@PathVariable ObjectId id, @RequestBody JournalEntry myEntry){
JournalEntry old = jounralEntryById(id);
if(old!=null){
myEntry.setId(id);
}
createEntry(myEntry);
return myEntry;
}
bhaiya jaldi se khatm krdo ye project fir ise ka frontend start krdo everyone is waiting
ok sir
This course should have been paid
There may be error in JournalEntryService class. If Autowired the constructor as follows then it works:
@Component
public class JournalEntryService {
@Autowired
public JournalEntryService(JournalEntryRepository journalEntryRepository) {
this.journalEntryRepository = journalEntryRepository;
}
private JournalEntryRepository journalEntryRepository;
public void saveEntry(JournalEntry journalEntry) {
journalEntryRepository.save(journalEntry);
}
}
Bhaia apka sahi ho gaya ho to bata do please help ho jayegi bhai ji please
{
"timestamp": "2024-06-19T07:02:14.396+00:00",
"status": 500,
"error": "Internal Server Error",
"path": "/students"
}
please help me...
bhai kese hua thik
@@_abhiishek_ bhai apka hua kya ye thik merko getAll m aur delete m aa raha hai 500
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.bson.types.ObjectId;
import java.io.IOException;
public class ObjectIdSerializer extends JsonSerializer {
@Override
public void serialize(ObjectId objectId, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeString(objectId.toHexString());
}
}
Please upload next series
I am waiting for your next series
findAll function not working
Same
@@anshulchoure5927 It works, the problem is we should not be using the collation attribute in the entity.
Instead write @Document(value = "journal_entries")