MongoDB Reference working-Programmershelpers

0
185
Spread the love

Reference Document

In this article, we learn MongoDB Reference working.If we have a lot of data in a table. we split data into two table and making the reference between two table using the primary and foreign key in the relational database.But in MongoDB reference managing some how different.In MongoDB reference in managed by Manual reference and DBRefs reference.

Prerequisite

It will good to cover my below articles before this.It helps to learn more about MongoDB.In which I explained.Click here Getting Start with MongoDB tutorial and Installation MongoDB on WIndows. and MongoDB projection working

Manual reference

In Manual reference simple _id of one document store another document just to make reference.when you run the query its show related data.The following is the example of manual reference.

DBRefs 

DBRefs reference is managed by one document to other using first document _id field, the name of collection and database name which optional.the document which locates multiple collections more easily link from a single collection using DBRefs.

There are three fields in DBRefs

  1. $ref: holds the name of the collection where reference establish.
  2. $id: holds the _id field of the referenced document.
  3. $db: optional field contains the name of the database in which the referenced document resides.

The following is the example  DBRefs reference.

Conclusion

I wish I could tell you that a great site of MongoDB.you just understands key element above post-MongoDB Reference working.More, detail about MongoDB reference, please click here Reference in MongoDB.You also read my previous lecture.I hope you will understand this lecture.Thank you for reading this lecture. Hope you got the idea. please share it.If you find any mistake or confusion Commit on reply section.