Assigning a variable to updating document operation and ram consuming

Hi,

is there any difference between

await User.findByIdAndUpdate(
  req.user.id,
  {
    $push: { noteNames: newNote } 
},{new: true}
).exec(function (err, DOC) {
  if (err) {
    return res.status(400).json({ success: false });
  }else {
    return res.status(200).json({
      success: true,
      doc: DOC
    });
  }
});

and

await User.findByIdAndUpdate(
  req.user.id,
  {
    $push: { noteNames: newNote } 
}
).exec(function (err) {
  if (err) {
    return res.status(400).json({ success: false });
  }else {
    return res.status(200).json({
      success: true,
    });
  }
});

according to mongodb server?

I know that they are different for backend server.

My concern is ram consuming on mongodb.
Does mongodb consume same ram at this two situation?

Hi @Taha_Tekin - Welcome to the Community :wave:

My concern is ram consuming on mongodb.
Does mongodb consume same ram at this two situation?

I believe the two queries you posted are very similar in nature, and thus would have negligible difference in actual RAM usage between them.

MongoDB uses RAM mainly to contain your working set, incoming connections, in-memory sorts, and others. MongoDB would always try to use as much RAM as possible to ensure that the server can be as performant as possible.

However, I’m not sure if I fully understand your question. Are you concerned that your operations using excessive RAM? Or is there a background story to the question? If overall RAM usage is your concern, you might want to take a look at How do I calculate how much RAM I need for my application

Best Regards,
Jason

1 Like

thank you @Jason_Tran

there is no background story. it’s just in my head.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.