MongoDB/Mongoose: Updating entire document with findOneAndUpdate()
<p>I want to use the <code>findOneAndUpdate()</code> method to either create a document if it doesn't exist, or update it if does exist. Consider the following code:</p>
<pre><code>SampleComment = new Comment({
    id: '00000001',
    name: 'My Sample Comment',
    ...
})
</code></pre>
<p>This is my attempt to find out if <code>SampleComment</code> aldready exists, and if so, update it, otherwise creating it:</p>
<pre><code>Comment.findOneAndUpdate(
    { id: SampleComment.id }, 
    { SampleComment }, // &lt;- NOT PASSING THE OBJECT
    { upsert: true, setDefaultsOnInsert: true }, 
    function(error, result) {
        ...
});
</code></pre>
<p>I'm trying to pass the Model-instance as an object in the second argument, but result is only returning the default values of the model. Same goes for the document itself.</p>
<p>How do I pass the entire object <code>SampleComment</code> correctly in the second argument?</p>