How to use findOneAndUpdate in MongoDB in Node
<p>Say previously I had inserted a document into a mongo collection.</p>

<pre><code>    MongoClient.connect(url, function(err,db){
      if(err) {throw err;}
      else {
        document = {action: "alert",
                    protocol: "udp",
                    port: "80",
                    _id: "12" }
        var collection = db.collection("connections");
        collection.insertOne(document, function(err,result){
          if (err) {throw err;}
          else {
            console.log("Successful")
            db.close();
          }
        }
      }
</code></pre>

<p>Now I want to update the protocol field. What I have with no luck so far is </p>

<pre><code>     MongoClient.connect(url, function(err,db){
       if (err) { throw err; }
       else {
         var collection = db.collection("connections");
         collection.findOneAndUpdate({_id: "12"}, {$set: {protocol: "http"}}, {new: true}, function(err,doc) {
           if (err) { throw err; }
           else { console.log("Updated"); }
         });  
       }
     });
</code></pre>

<p>Am I passing the wrong parameters to the findOneAndUpdate method? I connect to the database correctly. </p>