title: mongoose Error: cyclic dependency detected
body: <p>I wrote a service that analyses videos with <a href="https://www.npmjs.com/package/@google-cloud/video-intelligence" rel="nofollow noreferrer">Google Cloud Video Intelligence</a></p>
  <p>And I save the analysis results to the MongoDB with mongoose</p>
  <p>This is the model I use (I've simplified everything to avoid confusion):</p>
  <pre><code>// Video.js
  
  const mongoose = require('mongoose');
  
  const videoSchema = new mongoose.Schema({
      analysis_progress: {
          percent: { type: Number, required: true },
          details: {}
      },
      status: {
          type: String,
          enum: ['idle', 'processing', 'done', 'failed'],
          default: 'idle'
      }
  });
  
  module.exports = mongoose.model('Video', videoSchema);
  
  </code></pre>
  <p>When analyse operation ends, I call the function below and run <code>update</code> like this:</p>
  <pre><code>
  function detectFaces(video, results) {
     //Build query
      let update = {
          $set: {
              'analysis_results.face_annotations': results.faceDetectionAnnotations // results is the the test result
          }
      };
  
      Video.findOneAndUpdate({ _id: video._id }, update, { new: true }, (err, result) =&gt; {
          if (!err)
              return console.log(&quot;Succesfully saved faces annotiations:&quot;, video._id);
          throw err // This is the line error thrown
      });
  }
  </code></pre>
  <p>And this is the error I get:</p>
  <pre><code>Error: cyclic dependency detected
      at serializeObject (C:\Users\murat\OneDrive\Masaüstü\bycape\media-analysis-api\node_modules\bson\lib\bson\parser\serializer.js:333:34)
      at serializeInto (C:\Users\murat\OneDrive\Masaüstü\bycape\media-analysis-api\node_modules\bson\lib\bson\parser\serializer.js:947:17)
  ...
  </code></pre>
  <p>Solutions I tried:</p>
  <ol>
  <li>Added <code>{autoIndex: false}</code> inside db config.</li>
  </ol>
  <pre><code>mongoose.connect(process.env.DB_CONNECTION, {useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false, autoIndex: false });
  </code></pre>
  <ol start="2">
  <li>Removing <code>retryWrites=true</code> from Mongo URI structure. (I didn't have that parameter in my connection URI already)</li>
  </ol>
  <p>So, I think the source of the problem is that I am saving the whole test result but I don't have any other option to do that. I need to save as it is.</p>
  <p>I am open to all kinds of suggestions.</p>