MongoDB - Model One-to-One, One-to-Many Relationships Embedded Documents | Spring Boot | Java Techie

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ม.ค. 2025

ความคิดเห็น • 106

  • @sathishh2809
    @sathishh2809 4 ปีที่แล้ว +2

    How to insert sub-document value that should be refer with main document Id?

  • @ankesh3401
    @ankesh3401 4 ปีที่แล้ว +1

    bhai mza aa gya .. ultimate video

  • @ushamahesh9988
    @ushamahesh9988 2 ปีที่แล้ว +1

    Appreciate for your hard work and Thank you very much for this video.

  • @p.p526
    @p.p526 2 ปีที่แล้ว +1

    Sir, How we write query annotation if we want to add findByProduct from the list in the repository?

    • @Javatechie
      @Javatechie  2 ปีที่แล้ว

      Please check this out th-cam.com/video/qVNOw9TWwxo/w-d-xo.html

  • @Credi44
    @Credi44 3 ปีที่แล้ว

    How do i add only the product part of the json object into a different collection with a product key and map it to user object key

  • @krishnay9714
    @krishnay9714 4 ปีที่แล้ว +2

    You didn't perform update and delete operation on embedded document. Like, if i want to add one more product to particular user, how will we do that?

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว

      Simple just pass the existing id and based on id get the user object from DB
      Then while adding product object map this existing user to your request body

    • @krishnay9714
      @krishnay9714 4 ปีที่แล้ว +1

      Java Techie how to map existing user to request body? Could you please show some demo with code

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว +2

      Public void updateUser(@RequestBody product product){
      user=repository.findById(id);
      user.setProduct(product);
      Repository.save(user);
      }

    • @shridharpatil2314
      @shridharpatil2314 4 ปีที่แล้ว

      While doing like this it is replacing with existing product

  • @MohdDanishMansoori-o5k
    @MohdDanishMansoori-o5k ปีที่แล้ว +2

    thank you so much bro for getting this vidioo

  • @prayagbhasin9192
    @prayagbhasin9192 2 ปีที่แล้ว

    Sir if want to add data in collection product and collection addresss then what we can do ?

  • @gibranlara
    @gibranlara 6 ปีที่แล้ว +7

    Why all the people uses Embedded Documents? Not is more inefficient this strategy than use Referenced Documents?

    • @Javatechie
      @Javatechie  6 ปีที่แล้ว +3

      First of all if we are developing microservice approach we shouldn't go for association mapping this embedded documents only the way we can perform inner association and it will be more faster

  • @EaswarThondikulam
    @EaswarThondikulam 10 หลายเดือนก่อน +1

    Good Example. Thanks.

  • @vanshkhosla58
    @vanshkhosla58 2 ปีที่แล้ว

    Hi, can you please explain how we can use PUT Method to add 1 more array of object of Products in already created User.

  • @mathiasmartinez1011
    @mathiasmartinez1011 5 ปีที่แล้ว +2

    In real life, what is more used, embeded or reference documents?

  • @simpleTechGuide
    @simpleTechGuide 4 ปีที่แล้ว +2

    I tried to create one springboot app with mongodb, it is giving me 404 error when I hit through postman, while saving the entity, can u plz comment on this?

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว +1

      404 issue is always indicate about wrong URL mapping please give proper URL to access your rest endpoint
      Possible solution :
      1.check whether you followed proper package hierarchy or not
      2.if you are not following package hierarchy then you must need to enable component scan

    • @simpleTechGuide
      @simpleTechGuide 4 ปีที่แล้ว

      @@Javatechie is it necessary to add component scan in the controller?

    • @simpleTechGuide
      @simpleTechGuide 4 ปีที่แล้ว

      @@Javatechie I tried to use the similar package structure, by proper package hierarchy what do you mean, what do I need to do?

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว

      @@simpleTechGuide can you share your code through GitHub so that I can check this out

    • @simpleTechGuide
      @simpleTechGuide 4 ปีที่แล้ว

      @@Javatechie yeah will try to.share that

  • @abdulyasar3258
    @abdulyasar3258 3 ปีที่แล้ว +1

    @Java Techie sir. I got an error which shows _id :0 and _class : my model class path. Since I entered my data through postman and got successfully placed message. When I came to compass it's says like this sir.
    Kindly need your help sir

    • @Javatechie
      @Javatechie  3 ปีที่แล้ว

      Please configure Lombok in your IDE

    • @abdulyasar3258
      @abdulyasar3258 3 ปีที่แล้ว +2

      Sir even though if I add lambok dependency its still throwing like this only sir.. Please fix this bug for me sir.. I need your help

    • @Javatechie
      @Javatechie  3 ปีที่แล้ว

      You need to install in your IDE

    • @abdulyasar3258
      @abdulyasar3258 3 ปีที่แล้ว

      @@Javatechie can you please guide me sir?

    • @simranrohra9452
      @simranrohra9452 3 ปีที่แล้ว

      Hey i am facing the same issue how did you resolve it

  • @sarojsahoo8763
    @sarojsahoo8763 4 ปีที่แล้ว

    does Id annotation is required here as we are not having relationship concept here & How does Mongo knows it has to create Address Document from User Document . Is it derived from User

  • @Credi44
    @Credi44 3 ปีที่แล้ว +1

    What to do if i want to retrieve documents using product name?

    • @Javatechie
      @Javatechie  3 ปีที่แล้ว

      findByProductName()

    • @Credi44
      @Credi44 3 ปีที่แล้ว

      @@Javatechie i tried that, I'm getting 500 error- readstartdocument can only be called when currentbson is document not string

  • @PrateekSharma1712
    @PrateekSharma1712 2 ปีที่แล้ว +3

    Nice video. But I was looking for one to many Get query also. You have showcased getting users by address (one-to-one), but not getting users by product. Some cases that is important too. Your title says so. Also, having this structure where products go in user object, when say 100 users have bought 50 products and many more people will buy some of those 50 products. Won't it be a bulky database with repetitions?

  • @SivaNarayanan91
    @SivaNarayanan91 3 ปีที่แล้ว +1

    Worth Watching.....

  • @krishnayellina7053
    @krishnayellina7053 3 ปีที่แล้ว +1

    I really appreciate you for sharing great videos? One of the best video I have seen is your
    Java collection interview question vide. Could you do video on mongodb interview questions for java/springboot developer?

  • @devanshibhatt2305
    @devanshibhatt2305 5 ปีที่แล้ว

    How can i fetch the list of User's , who are having product as mobile..

  • @bhargavi_Veeru
    @bhargavi_Veeru 2 ปีที่แล้ว +1

    Great Tutorial !! Really very helpful.. Can you please make a vedio on Spring Boot with mongodb and elastic search

    • @Javatechie
      @Javatechie  2 ปีที่แล้ว

      Already did that please checkout my spring boot playlist

  • @manishagarwal6134
    @manishagarwal6134 4 ปีที่แล้ว +1

    Any video on pagination in Spring. eg. when doing product search based on sorting on few fields lets say price of product

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว +1

      This scenario already covered in spring data jpa

    • @manishagarwal6134
      @manishagarwal6134 4 ปีที่แล้ว +1

      @@Javatechie thanks.. I will check it out

  • @prashantbangilwar4893
    @prashantbangilwar4893 6 ปีที่แล้ว +1

    Hi basant ...how to work with procedure,functions and trigger in mongo db

    • @Javatechie
      @Javatechie  6 ปีที่แล้ว +1

      Procedure I never tried with mongo I will check and let you know

    • @prashantbangilwar4893
      @prashantbangilwar4893 6 ปีที่แล้ว

      Thanks basant

  • @shaikshasayyad131
    @shaikshasayyad131 6 ปีที่แล้ว +1

    Hello!!! Basant
    should we have to use NoSql DB instead SQL DB in microservice?

    • @Javatechie
      @Javatechie  6 ปีที่แล้ว +2

      It's good to use NoSQL over SQL in microservice architecture .
      Please Go through my SQL vs NoSQL tutorial you will get clear idea on it ....

    • @shaikshasayyad131
      @shaikshasayyad131 6 ปีที่แล้ว +1

      Thank you for your quick response

  • @el_yisusT
    @el_yisusT 5 ปีที่แล้ว +1

    What happen if you restart the spring boot app? It's the same like H2? Thanks

    • @Javatechie
      @Javatechie  5 ปีที่แล้ว +1

      No H2 is in memory DB but mongo can store data for long , until unless you delete it

    • @el_yisusT
      @el_yisusT 5 ปีที่แล้ว

      @@Javatechie Thanks

  • @javalok9575
    @javalok9575 4 ปีที่แล้ว +1

    can you please make video how to use @Ref and test from postman ? thanks

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว

      I need to check this , will do

    • @javalok9575
      @javalok9575 4 ปีที่แล้ว +1

      @@Javatechie thanks for reply , i tried but could not succeeded. I'd be glad if you make video

  • @sarojsahoo8763
    @sarojsahoo8763 4 ปีที่แล้ว

    Isnot it necessary to annotate @Document in Address and Product classes

  • @linahammami4263
    @linahammami4263 4 ปีที่แล้ว +1

    Hello ,;
    How to get the list of products, thank you

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว

      Simply you can call repository.findAll();

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว

      Do you have entity with name Product if Yes create ProductRepository extends from Jpa repository
      Then use ProductRepository.findAll()

  • @noeliadiazayllon1998
    @noeliadiazayllon1998 3 ปีที่แล้ว

    Excuse me but I don't understand why we don't create here a Service but if we connect to Mysql database we do. If you could explain it to me it would help a lot! Thank you!!

  • @gauravkumardwivedi2290
    @gauravkumardwivedi2290 4 ปีที่แล้ว +1

    GREAT👍👏, How to maintain PK like our JPA generationType.AUTO?

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว +1

      No this is bit tricky , you need to create sequence manually I mean using java code

    • @gauravkumardwivedi2290
      @gauravkumardwivedi2290 4 ปีที่แล้ว +1

      @@Javatechie thanks I checked on google I found that we can maintain through UUID.

  • @devanshsharma4273
    @devanshsharma4273 2 ปีที่แล้ว +1

    So easy...now here's the task...create the separate collection and acces that collection using dbref...can you do this??

    • @Javatechie
      @Javatechie  2 ปีที่แล้ว +1

      Yes we can

    • @devanshsharma4273
      @devanshsharma4273 2 ปีที่แล้ว +1

      @@Javatechie how we can... I got stuck at one point... please help me 🙏🏻

    • @Javatechie
      @Javatechie  2 ปีที่แล้ว

      Okay sure let me check

  • @ilalit8254
    @ilalit8254 3 ปีที่แล้ว

    Hi Brother, Could you please make and video for PUT and delete where the objects inside arrays will be deleted.

    • @greenguitar2111
      @greenguitar2111 3 ปีที่แล้ว

      Lalit bhai do you know how to get users by product name in this video?

  • @venkataramanaakkineni3583
    @venkataramanaakkineni3583 5 ปีที่แล้ว +1

    How can we update embedded documents like products

    • @krishnay9714
      @krishnay9714 4 ปีที่แล้ว +1

      @Java Techie Please answer this question

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว +1

      Answered on your comment just go through it

  • @LORD_PANDUKA
    @LORD_PANDUKA 4 ปีที่แล้ว +1

    Why can't you use Intellij Idea community edition? This IDE is sucks.

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว

      Yes am using intellij dude , this is old video

  • @greenguitar2111
    @greenguitar2111 3 ปีที่แล้ว +1

    Basant sir can you help me with the code of finding users by product name, I am working on a project with same logic and i am stuck on this for several days. since products part is array I am getting confused please help me.

    • @Javatechie
      @Javatechie  3 ปีที่แล้ว

      Simply get list of users then from users get the products and iterate with filter product name if any matches found then create new array list and add user object and return it

  • @sureshkrishnanmuthusamy5012
    @sureshkrishnanmuthusamy5012 3 ปีที่แล้ว +1

    Kindly explain the two collection and fetch the data from mongodb using spring boot

  • @nuwanharsha1361
    @nuwanharsha1361 4 ปีที่แล้ว +1

    Great tutorial ! ❤ But I have some questions. How to model this in many to many relationship in spring boot with mongo db? How to handle cascading operations in that case?

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว +1

      Hi Harsha ,
      This is one difference between RDBMS and NoSQL .
      We can't handle association mapping in NoSQL because it's not ment for transactional data .
      We have workaround on it that we can maintain mapping as embedded documents

  • @amaradhipadmaja9232
    @amaradhipadmaja9232 4 ปีที่แล้ว +1

    Nice tutorial, Thanks you for amazing content. One question, like in Spring Data JPA we use OneToOne annotations to have Product Object, Here how will "USer class"know internally that it should do oneToOne mapping here without annotations ? Please explain

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว

      Without annotation it's not possible to make relationship between entity

    • @marcosalonsoibanezalcas7112
      @marcosalonsoibanezalcas7112 4 ปีที่แล้ว

      @@Javatechie como lo aplicaría con referencias @DBRef

  • @kaioid
    @kaioid 3 ปีที่แล้ว +1

    thank you so much sir

  • @magiclogic6800
    @magiclogic6800 3 ปีที่แล้ว

    Make video for insert/fetch country, state, city using mongodb thankful your hardwork.

  • @hadamakebe4991
    @hadamakebe4991 4 ปีที่แล้ว +1

    thank you for tuto

  • @mathiasmartinez1011
    @mathiasmartinez1011 5 ปีที่แล้ว +2

    The example of the CRUD of spring boot and mongodb I think is great, but I suffered to understand your pronunciation in english, for next time try to improve in order to enjoy your great tutorials. Just a good advice

    • @Javatechie
      @Javatechie  5 ปีที่แล้ว

      Hi Mathias,
      Thanks for your interest , going forward will take care this 👍

    • @krishnay9714
      @krishnay9714 4 ปีที่แล้ว

      Its not a crud operation. Its is only get and post.

  • @_modiX
    @_modiX 6 ปีที่แล้ว +1

    ok

  • @Azimofffable
    @Azimofffable 5 ปีที่แล้ว +3

    Pleaseeeeee improve your pronunciation pleaseeeeeeee

    • @Javatechie
      @Javatechie  5 ปีที่แล้ว +2

      Hi Qurban , I really apologies for this , as this is my initial video so prepare video with lot of nervousness
      So I would like to to suggest you to go through my latest video , hopefully you will love those content

    • @BalajiRancho
      @BalajiRancho 4 ปีที่แล้ว

      @@Javatechie Hi, I am having null values inserted into the db, can you explain the reason why the values in User class are passing as null ?

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว +1

      @@BalajiRancho did you add getter and setter method in your entity

    • @amaradhipadmaja9232
      @amaradhipadmaja9232 4 ปีที่แล้ว +5

      @@Javatechie Basant, you're really humble in doing so and being apologetic(Which you dint need to be) ! Your video tutorial are really life changer for me . I can clear my interviews with so much confidence, because its very clear for understanding concepts. Thank you so much !!!

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว

      Thank you so much Amaradhi , glad to hear this

  • @mrsdet2045
    @mrsdet2045 4 ปีที่แล้ว +1

    How to auto increment the Id?

    • @Javatechie
      @Javatechie  4 ปีที่แล้ว +1

      As far I know there is no direct feature to use Auto generate id
      I will check and update okay

    • @mrsdet2045
      @mrsdet2045 4 ปีที่แล้ว +1

      @@Javatechie thank you 🙏