MongoDB : Normalize Database reference (DBRefs)

The joy of a Document database is that it eliminates lots of Joins. Your first instinct should be to place as much in a single document as you can. Because MongoDB documents have structure, and because you can efficiently query within that structure there is no immediate need to normalize data like you would in SQL. In particular any data that is not useful apart from its parent document should be part of the same document.

This is not so much a “storage space” issue as it is a “data consistency” issue. If many records will refer to the same data it is more efficient and less error prone to update a single record and keep references to it in other places.

DBRef documents resemble the following document:

{ "$ref" : <value>, "$id" : <value>, "$db" : <value> }

Consider a document from a collection that stored a DBRef in a creator field:

  "_id" : ObjectId("5126bbf64aed4daf9e2ab771"),
  // .. application fields
  "creator" : {
                  "$ref" : "creators",
                  "$id" : ObjectId("5126bc054aed4daf9e2ab772"),
                  "$db" : "users"

The DBRef in this example points to a document in the creators collection of the users database that has ObjectId("5126bc054aed4daf9e2ab772") in its _id field.

Consider the following operation to insert two documents, using the _id field of the first document as a reference in the second document:

original_id = ObjectId()

    "_id": original_id,
    "name": "Broadway Center",
    "url": ""

    "name": "Erin",
    "places_id": original_id,
    "url":  ""

Then, when a query returns the document from the people collection you can, if needed, make a second query for the document referenced by the places_id field in the places collection.

Reference link for details :

MongoDb Tutorial by Premaseem (Free video course on MongoDB)

Hi Friends,

I am certified MongoDb expert. I though to share my knowledge with all, so that this entire world might get benefitted by it. It’s a free youtube video series with short lecture  covering different topics (31 topics).

Free video tutorial link :

mongoDB tutorial on youtube.png

Use this free tutorial and share it with friends 🙂

Free online web based Terminals and IDEs on cloud

Whenever we want to learn some thing, there is a fight to setup machine, environment etc before we can begin, thanks to new cloud technology now you can start instantly using free online web based Terminals and IDEs on cloud




Free Online Linux Terminal to practice commands


If you want to try out linux commands without bothering to to through installation then try the free online linux terminal to practice commands.

This is simple


This has some additional features :–A nice site to learn advanced frameworks like Angular JS

This is the era of eLearning. By virtue of eLearning you can avail the best instructor with nice and interactive training material and too at the time and pace you like. Today I completed an Angular course which I like to recommend you in case if you want to learn things in an interactive way. 

The course is hands on course with challenges, hints and tutorial videos which are both verbal explanation with technical code walk through. Course is divided in modules and levels of challenges to track the progress.

Try it Winking smile