Node.js and MongoDB using Mongoose. Using findByIdAndUpdate vs Manual

are there any drawbacks to using findByIdAndUpdate and doing it manually. I noticed that findByIdAndUpdate drops my mongo connection, and read that you should try to keep connection open, only close when you close your app. Is this the case, and if so, is there a config setting that I am not seeing for findByIdAndUpdate, that keep the connection on?

updateItemById: function(id, updateObj, options, callback){
  //OPTION 1
      Badge.findById(id, null , function(err, doc){
    doc.update(updateObj, function(err, numberAffected, raw){
    if (err) return handleError(err);
         Badge.findById(id, null , function(err, doc){
                 callback(doc);
             });
        });
   });
  //OPTION 2
  Badge.findByIdAndUpdate(id, updateObj, options, function(err, data){
        callback(doc);
  });
 }

findByIdAndUpdate should be faster (as long as the driver and mongoose are correctly programmed), because:

With Option 1:

  • Fetch the object by ID
  • Transform it into JavaScript object
  • Update object in client
  • Send back to DB
  • Calculate and save changes
  • Send it back
  • Transform into JavaScript object

With Option 2:

  • Find document in Database
  • Calculate and apply changes as atomic operation
  • Send object back
  • Transform into JavaScript object

As you can see, the second options does require less steps and therefore should be faster.

Bonus: The code is more readable.