Rest Api Blog Posts

How to reference documents in Mongodb

This article is helpful for those who are seriously looking and finding the usecase of reference documents in MongoDB. Referencing comes when we are saving data to database , that thing we obiously do through axios (Most Popular). Just place the below code inside any router where you want to and check the results.
Saving refs to other documents works the same way you normally save properties, just assign the _id value:
let Team = require('./team.model');
let Player = require('./player.model');
const team = new Team({
_id: new mongoose.Types.ObjectId(),
Name: 'KoderPlace',

0 Likes 28 Views