title: Select random document with filter with pymongo?
body: <p>I <a href="https://stackoverflow.com/a/33578506/258483">found, that to select random document</a>, I need to use <code>$sample</code> command:</p>
  
  <pre><code>// Get one random document from the mycoll collection.
  db.mycoll.aggregate(
     { $sample: { size: 1 } }
  )
  </code></pre>
  
  <p>but what if I need to filter documents and THEN take random one?</p>
  
  <p>I am processing documents, which are not processed yet with</p>
  
  <pre><code>query = {'start_time': {'$exists': False}}
  hp_entries = mongo.hyperparameters_collection.find(query)
  </code></pre>
  
  <p>How would I do with random?</p>