Hi @Gaurav_Gupta,
As @Doug_Duncan mentioned, definitely consider whether referencing is the best path for your data model and use case. This approach often feels comfortable coming from an RDBMS data modelling background, but may not be taking advantage of some of the flexibility that MongoDB enables. For best performance and outcomes with MongoDB, you need to focus on modelling to support your common application usage rather than strictly normalising data.
If you do want to relate documents (which can definitely be appropriate), I strongly recommend using manual referencing. This approach provides the most flexibility if you are likely to want to perform additional manipulation in future (such as using $lookup
and other aggregation operators).
DBRefs use an older convention which represents references using a document format:
{ "$ref" : <value>, "$id" : <value>, "$db" : <value> }
The DBRef convention uses $
-prefixed keys and generally has limited support in modern drivers, tools, and aggregation queries. The convention isn’t officially deprecated, but isn’t a great choice for modern applications.
In addition to the Building with Patterns series of blog posts mentioned in Doug’s earlier comment , I would also consider taking some of the free online courses at MongoDB University. There’s a MongoDB for Developers Learning Path with some course recommendations, or you could also dive into courses like M320: Data Modelling if you already have some MongoDB experience.
Regards,
Stennie