title: NodeJS - MongoDB computation overhead
body: <p>I have a scenario in which I have to update 2 mongodb collections.
  There are 2 collections: Ads, Likes</p>
  
  <p><strong>Scenario 1:</strong> I insert a document in <strong>likes</strong> table with the <strong>ad._id</strong> and <strong>user._id</strong> and on successful insertion I update the Ad's property likesCount with like's length using the query <strong>db.likes.find({ad._id}).count()</strong>. After that I will query <strong>db.ads.find()</strong> to fetch all ad's records. Ad's document will have the respective likes count already in them.</p>
  
  <p><strong>Scenario 2:</strong> I only insert a document in <strong>likes</strong> table with the <strong>ad._id</strong> and <strong>user._id</strong>. After that I will query <strong>db.ads.find()</strong> to fetch all ad's records and process each Ad's document to set the likesCount field on run time with the query <strong>db.likes.find({ad._id}).count()</strong>.</p>
  
  <p>I want to know which scenario has more overhead in terms of computation and processing given that All Ads query will be hit only 1 time in a day.</p>