MongoDB Reference Working


Reference Document

In this article, we learn MongoDB Reference working. In MongoDB reference in managed by Manual reference and DBRefs reference. 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 somehow different.


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


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