WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

>MongoDB - Relationships


MongoDB - Create Collection: In this chapter Relationships in MongoDB.

Relationships can be both 1:1, 1:N, N:1 or N:N

Let us don't forget the case of storing addresses for users.

Following is the sample document structure of person document


   "_id":ObjectId("541221455412"),
   "call": "ADITYA",
   "contact": "565114",
   "dob": "01-01-1975"
is the pattern file shape of address file

   "_id":ObjectId("21215412154"),
   "constructing": "22 A, Indiana Apt",
   "pincode": 123456,
   "town": "LA",
   "nation": "CA"
 

Modeling Embedded Relationships

In the embedded approach, we will embed the cope with document inside the consumer file.

   "_id":ObjectId("52ffc33cd85242f436000001"),
   "touch": "987654321",
   "dob": "01-01-1991",
   "call": "Tom Benzamin",
   "address": [
      
         "building": "22 A, Indiana Apt",
         "pincode": 123456,
         "city": "Los Angeles",
         "state": "California"
      ,
      
         "building": "170 A, Acropolis Apt",
         "pincode": 456789,
         "town": "Chicago",
         "kingdom": "Illinois"
      
   ]
 

Modeling Referenced Relationships

This is the method of designing normalized dating. In this method, each the user and cope with documents can be maintained one at a time however the person file will comprise a area so that it will reference the cope with report's identity discipline.

   "_id":ObjectId("52ffc33cd85242f436000001"),
   "contact": "987654321",
   "dob": "01-01-1991",
   "name": "Tom Benzamin",
   "address_ids": [
      ObjectId("52ffc4a5d85242602e000000"),
      ObjectId("52ffc4a5d85242602e000001")
   ]

This is the approach of designing normalized dating. In this method
>var result = db.Users.FindOne("call":"Tom Benzamin","address_ids":1)
>var addresses = db.Cope with.Discover("_id":"$in":result["address_ids"])




Welookups is optimized for learning.Copy right 2018 - 2019 kumar aditya singh .
All Right Reserved and you agree to have read and accepted our term and condition.
All Rights Reserved.