es6 spread operator - mongoose result copy : <p>I'm developping an express js API with mongo DB and mongoose.</p>

<p>I would like to create an object in Javascript es6 composed of few variables and the result of a mongoose request and want to do so with es6 spread operator :</p>

<pre><code>MyModel.findOne({_id: id}, (error, result) =&gt; {
   if (!error) {
      const newObject = {...result, toto: "toto"};
   }
});
</code></pre>

<p>The problem is that applying a spread operator to <strong>result</strong> transform it in a wierd way:</p>

<pre><code>newObject: {
   $__: {
      $options: true,
      activePaths: {...},
      emitter: {...},
      getters: {...},
      ...
      _id: "edh5684dezd..."
   }
   $init: true,
   isNew: false,
   toto: "toto",
   _doc: {
      _id: "edh5684dezd...",
      oneFieldOfMyModel: "tata",
      anotherFieldOfMyModel: 42,
      ...
   }
}
</code></pre>

<p>I kind of understand that the object result is enriched by mongoose to permit specific interactions with it but when I console.log before doing so it depict a simple object without all those things.</p>

<p>I would like not to cheat by doing <strong>...result._doc</strong> because I abstract this part and it won't fit that way. Maybe there is a way to copy an object without eriched stuff.</p>

<p>Thank you for your time.</p>
