Step-by-Step Tutorial: How to Integrate MongoDB in Your Spring Boot Application

Поділитися
Вставка
  • Опубліковано 28 лип 2024
  • 🟡 Get 1 to 1 coaching with me: topmate.io/engineeringdigest
    🟡 Donate: paypal.me/engineeringdigest
    🟡 Perks: www.youtube.com/@EngineeringD...
    🔴 Instagram: / thevipulvats
    🔴 GitHub: github.com/thevipulvats
    🔴 Twitter: / thevipulvats
    🔴 LeetCode: leetcode.com/thevipulvats
    🔴 LinkedIn: / thevipulvats
    🔴 Discord: / discord
    🟢 Source code: github.com/chotabheeeeem/jour...
    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

КОМЕНТАРІ • 130

  • @asaiteja_23
    @asaiteja_23 4 місяці тому +9

    Instead of web series, i’m using UA-cam 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.

    • @asaiteja_23
      @asaiteja_23 4 місяці тому +1

      Also, Please start Frontend Framework course too. Like react or angular

    • @amitkadam2354
      @amitkadam2354 18 днів тому

      Should start first javascript in brief then angular

  • @ankitsrivastava2750
    @ankitsrivastava2750 7 місяців тому +3

    The way you have explained the concept & implementation, its flawless. Thanks a lot to you for creating contents.

  • @kidsnkiddi2337
    @kidsnkiddi2337 9 місяців тому +1

    thank you sir for this amazing course. ❤

  • @dProfessor_
    @dProfessor_ 8 місяців тому +1

    marvelous concept

  • @sawleshwarkaratharva809
    @sawleshwarkaratharva809 9 місяців тому

    Debug process was new to me. Thanks for walkthrough.

  • @dProfessor_
    @dProfessor_ 8 місяців тому

    Eagerly waiting for the upcoming videos

  • @rizwanshahid1447
    @rizwanshahid1447 3 місяці тому

    Thank you so much, Sir. great work. every video worth of million views

  • @OzonexAnime
    @OzonexAnime Місяць тому

    God Level Explanation and This guy deserves popularity

  • @user-ui2tj7yy1t
    @user-ui2tj7yy1t 8 місяців тому

    It's just amazing, explanation is soo good. Keep uploading...

    • @EngineeringDigest
      @EngineeringDigest  8 місяців тому +1

      Thank you brother, it will be a huge help if you can share this course on LinkedIn.

  • @krishnendudutta1465
    @krishnendudutta1465 3 місяці тому

    Awesome, great content

  • @amankumarmandal1513
    @amankumarmandal1513 4 місяці тому

    I am fully new in java field but your video is too good 😊. Way of learning great .

  • @prathameshpawar1912
    @prathameshpawar1912 Місяць тому

    Bahut Badhiya, sab kuch bina bakwas ke!!!

  • @tarunsinghtomar8623
    @tarunsinghtomar8623 Місяць тому

    Great Explanation

  • @dProfessor_
    @dProfessor_ 8 місяців тому

    very beautifully explained

  • @Sarka.r
    @Sarka.r 2 місяці тому

    tagda lage raho munna bhai, the language you used that' s the connection between you and us.

  • @jaikumar2435
    @jaikumar2435 Місяць тому

    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

  • @shwetachoudhary9003
    @shwetachoudhary9003 2 місяці тому

    the explanation is soo perfect and easy

  • @me-guruji6461
    @me-guruji6461 11 днів тому

    One Thing i want to add i thought spring learning will be difficult but its easy Thanks @ED

  • @creativemind9323
    @creativemind9323 11 днів тому

    so amazing playlist sir

  • @user-nl1og3pz2z
    @user-nl1og3pz2z 4 місяці тому

    Sirji Love your videos! Please error handling and uske best practices bhi cover karna!

  • @anantshukla6395
    @anantshukla6395 Місяць тому

    Your teaching skill is outstanding ...

  • @ashaysaoji2273
    @ashaysaoji2273 12 днів тому

    Mast lagg rahe hai ab takk videos

  • @baadal440
    @baadal440 26 днів тому

    Great explanation sir, thanks a lot

  • @AzfarSyed-kh9iy
    @AzfarSyed-kh9iy 2 місяці тому

    Very nice tutorial

  • @mainakmondal5228
    @mainakmondal5228 3 місяці тому

    Excellent.

  • @mdsaif4696
    @mdsaif4696 5 місяців тому

    Nice video

  • @panchaljayutube
    @panchaljayutube 6 місяців тому

    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?

  • @rudrapratap317
    @rudrapratap317 Місяць тому

    Best Tutorial Ever, Thank you bhai

  • @varshinisalian3214
    @varshinisalian3214 28 днів тому

    Fab❤

  • @anilprajapati9511
    @anilprajapati9511 2 місяці тому

    best series on youtube

    • @EngineeringDigest
      @EngineeringDigest  2 місяці тому

      Thanks a lot! Please share this playlist on LinkedIn. It will be a huge support.

  • @ahmednandoliya7950
    @ahmednandoliya7950 7 місяців тому

    Please upload next series
    I am waiting for your next series

  • @adityasachan6833
    @adityasachan6833 Місяць тому

    killed it

  • @hamdanahmed3565
    @hamdanahmed3565 2 місяці тому

    Lovely

  • @Neural_Network_News
    @Neural_Network_News 3 місяці тому

    Nice tutorials. Please create advance tutorials on spring boot

  • @Piyush_9
    @Piyush_9 7 днів тому

    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

  • @user-fe3wc8wp5b
    @user-fe3wc8wp5b 5 місяців тому

    sir aapne mongoTemplate kyu nhi use kiye...?
    agr ho skte to MongoTemplate pe video bna dijiye

  • @ananjaygurjar
    @ananjaygurjar 6 місяців тому

    Doesn't the db thread block the thread? Awesome video btw

  • @sonalagrawal-up3bq
    @sonalagrawal-up3bq День тому

    Why does postman shows date and time as id while the db shows an actual auto generated id?

  • @Yogeshwar-cv1ci
    @Yogeshwar-cv1ci 2 місяці тому

    MongoRepository class are not inherited why ? And @Document @Id shows error

  • @greenskull4972
    @greenskull4972 8 днів тому

    Loved the content. I am waiting for the React series with Javascript even if it comes as a paid course. !!!!!

  • @tanujverma1126
    @tanujverma1126 2 місяці тому +2

    Sir my getAll()
    Deletebyid()
    update()
    not working
    and not able to debug can you help;

    • @vaibhavzalte4430
      @vaibhavzalte4430 Місяць тому +1

      @Document(collation="company") insted of this use
      @Document(collection = "journal_entries") small diffrance

  • @wonderweebwoman
    @wonderweebwoman 2 місяці тому

    How to debug was the cherry on top!

    • @tanujverma1126
      @tanujverma1126 2 місяці тому

      bro my getAll()
      Deletebyid()
      update()
      not working
      and not able to debug can you help;

    • @wonderweebwoman
      @wonderweebwoman 2 місяці тому

      @@tanujverma1126 Sure! give some details

    • @wonderweebwoman
      @wonderweebwoman 2 місяці тому

      @@tanujverma1126 sure bro, give some details

  • @anandvidyasagar
    @anandvidyasagar 3 місяці тому

    Is there a github link to these code lessons?

  • @pakistanmerenazarsay7174
    @pakistanmerenazarsay7174 3 місяці тому

    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

  • @devsharma402
    @devsharma402 Місяць тому +1

    Get call showing internal error in postman and code return perfectly how can i resolve it ?

  • @Uzair_Anwar2299
    @Uzair_Anwar2299 Місяць тому

    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,

  • @bishmayranjansahoo6599
    @bishmayranjansahoo6599 17 днів тому

    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.

  • @ROHANKUMAR_
    @ROHANKUMAR_ Місяць тому

    can anyone explain why it is happen

  • @ShubhamAwasthi-o8k
    @ShubhamAwasthi-o8k 26 днів тому

    Can we use @Service annotation instead of @Component for creating the bean in the service class? Btw teaching skills are outstanding.

  • @neerajverma942
    @neerajverma942 Місяць тому

    thanks for this tutorial easily understandable . debug cocept is new for me great sir 😎😎

  • @webbygamingftw2038
    @webbygamingftw2038 Місяць тому

    Sir mere get call work nhi kr rhe error show ho rha plz help

  • @yuvrajchandra2136
    @yuvrajchandra2136 29 днів тому

    I have just 1 doubt , why did we not use @Repository annotation in repo class and @Service in service class ?

    • @amitkadam2354
      @amitkadam2354 18 днів тому

      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

  • @unknown_encoder
    @unknown_encoder 5 місяців тому

    Local date time throw error

  • @kshitizsaini4507
    @kshitizsaini4507 2 місяці тому

    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. ?

  • @targetsubconscious3003
    @targetsubconscious3003 2 місяці тому +1

    make series on microservices

  • @mohdfarhan1038
    @mohdfarhan1038 2 місяці тому

    eclipse m p banao backend and frontend connect kr bake

  • @IamBhagat07
    @IamBhagat07 22 дні тому

    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

    • @AnshulyouT
      @AnshulyouT 16 днів тому

      bro update ur code with
      @Putmapping("id/{myId}") and where ever sir placed id replace it with myId .

  • @OpSorryYt_2.0M_Tech
    @OpSorryYt_2.0M_Tech 7 місяців тому +1

    Nice Voice Sir. I know everything but I am a fresher Sir can you help me for complete my fresher teg 😊😅

  • @VishnuVardhanReddyKondur
    @VishnuVardhanReddyKondur Місяць тому

    Sir I am facing an issue regarding the connection to database is there a way you can help me out?

  • @baadal440
    @baadal440 26 днів тому

    🌟🌟🌟🌟🌟

  • @sawanverma3605
    @sawanverma3605 2 місяці тому

    In this video we can say this is crud operation?

    • @EngineeringDigest
      @EngineeringDigest  Місяць тому

      Yes

    • @sawanverma3605
      @sawanverma3605 Місяць тому

      ​@@EngineeringDigestin service class by you use @component rather than using @service.

  • @codedecode8686
    @codedecode8686 5 місяців тому +1

    findAll function not working
    Can anyone help me

    • @sadiqpatel8519
      @sadiqpatel8519 3 місяці тому +1

      It works, the problem is we should not be using the collation attribute in the entity.
      Instead write @Document(value = "journal_entries")

    • @pakistanmerenazarsay7174
      @pakistanmerenazarsay7174 3 місяці тому +1

      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

  • @himanshujoshi1163
    @himanshujoshi1163 Місяць тому

    MySQL se kese kare 🥺

  • @dhananjaybhagwat365
    @dhananjaybhagwat365 3 місяці тому

    I’m getting server error (500) for get http but it is working for getbyid

    • @shrutiraval6806
      @shrutiraval6806 25 днів тому

      Have you solve this error? i am also getting this error

    • @dhananjaybhagwat365
      @dhananjaybhagwat365 24 дні тому

      @@shrutiraval6806 yes

    • @IamBhagat07
      @IamBhagat07 22 дні тому

      @@shrutiraval6806 I think you can try @Document only instead of @Document(what ever you write)

  • @Mahesh_pushpad
    @Mahesh_pushpad 6 місяців тому

    Content is good ❤ but Why you use mongodb instead of mysql

  • @soumyadas9939
    @soumyadas9939 2 місяці тому

    Great explanation but one thing how will I remember all this? This topic is quite vast.

  • @ROHANKUMAR_
    @ROHANKUMAR_ Місяць тому

    it is showing error in mongorepositry

    • @VV-ps8rt
      @VV-ps8rt 10 днів тому

      after updating pom.xml, right click --> maven --> reload project

  • @kamallochandas2124
    @kamallochandas2124 Місяць тому

    {
    "timestamp": "2024-06-19T12:20:00.947+00:00",
    "status": 500,
    "error": "Internal Server Error",
    "path": "/journal"
    }
    please help anyone .........

    • @shrutiraval6806
      @shrutiraval6806 24 дні тому

      have you solve the error?

    • @AnshulyouT
      @AnshulyouT 16 днів тому

      @@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 😃

  • @codedecode8686
    @codedecode8686 5 місяців тому

    findAll function not working

    • @pakistanmerenazarsay7174
      @pakistanmerenazarsay7174 3 місяці тому

      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

  • @Arjun2mkap3929
    @Arjun2mkap3929 26 днів тому +1

    25:21

  • @devsharma402
    @devsharma402 Місяць тому +1

    Spring boot ka sara code sahi likha h lakin api hit ni error 404 ara h kyo ?

    • @chaitanyakashyap9520
      @chaitanyakashyap9520 День тому +1

      Bhai Sahi Ho gaya kya PLease bhai bata do kese thik kiya

    • @devsharma402
      @devsharma402 День тому

      @@chaitanyakashyap9520 bhai ek baar postman ko refresh karo fir get ki api hit karo

    • @devsharma402
      @devsharma402 День тому

      @@chaitanyakashyap9520 aur code check karo apna shyd koi problem ho

    • @devsharma402
      @devsharma402 День тому

      @@chaitanyakashyap9520 ha hogaya mera sahi

  • @Arjun2mkap3929
    @Arjun2mkap3929 29 днів тому

    13:47

  • @chocolateboy7001
    @chocolateboy7001 Місяць тому

    Muze samjane mein taklif ho rahi hai.. Help me sir..

  • @Himanshu-vi1jv
    @Himanshu-vi1jv 4 місяці тому

    bhaiya jaldi se khatm krdo ye project fir ise ka frontend start krdo everyone is waiting

  • @siddharthsaurav3657
    @siddharthsaurav3657 Місяць тому

    This course should have been paid

  • @namangarg7964
    @namangarg7964 27 днів тому

    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;
    }

  • @rizwanshahid1447
    @rizwanshahid1447 3 місяці тому +2

    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);
    }
    }

    • @chaitanyakashyap9520
      @chaitanyakashyap9520 5 днів тому

      Bhaia apka sahi ho gaya ho to bata do please help ho jayegi bhai ji please

  • @HarshVardhanTiwari-md3dz
    @HarshVardhanTiwari-md3dz Місяць тому

    {
    "timestamp": "2024-06-19T07:02:14.396+00:00",
    "status": 500,
    "error": "Internal Server Error",
    "path": "/students"
    }
    please help me...

    • @_abhiishek_
      @_abhiishek_ 28 днів тому

      bhai kese hua thik

    • @prajjwal_gaming
      @prajjwal_gaming Годину тому

      @@_abhiishek_ bhai apka hua kya ye thik merko getAll m aur delete m aa raha hai 500

  • @sanskarram992
    @sanskarram992 4 місяці тому

    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());
    }
    }

  • @xypq8310
    @xypq8310 Місяць тому +1

    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]

    • @user-vj8vl8yt6q
      @user-vj8vl8yt6q Місяць тому +1

      Check application.propeties file is correct or not

  • @ahmednandoliya7950
    @ahmednandoliya7950 7 місяців тому

    Please upload next series
    I am waiting for your next series

  • @codedecode8686
    @codedecode8686 5 місяців тому

    findAll function not working

    • @anshulchoure5927
      @anshulchoure5927 5 місяців тому

      Same

    • @sadiqpatel8519
      @sadiqpatel8519 3 місяці тому

      @@anshulchoure5927 It works, the problem is we should not be using the collation attribute in the entity.
      Instead write @Document(value = "journal_entries")