title: Mongodb: how to get the first document from database and then delete it
body: <p>I'm developing an app and I'm using for the first time MongoDB.</p>
  
  <p>I'm experiencing some problems with usage, because documentation seems to be outdated and even the answers here seem to be related to previous version, so several functions are deprecated.</p>
  
  <p>I would like to get and then delete the first document of my database.</p>
  
  <p>I have tried the following code:</p>
  
  <pre><code>const mongodb = require('mongodb');
  const MongoClient = mongodb.MongoClient;
  const url = &lt;my mongodb url&gt;;
  
  MongoClient.connect(url, { useNewUrlParser: true, useUnifiedTopology: true }, function (err, client) {
      if (err) {
          console.error('Unable to connect to the mongoDB server. Error:', err);
      } else {
          const db = client.db('myFirstDb').collection('myList');
  
          db.find().toArray((err, items) =&gt; {
              console.log(items.length)
          });
  
          db.updateOne({}, {$pop: {myList: -1}}, function (err, result) {
              console.log('Done');
          });
  
          client.close();
      }
  });
  </code></pre>
  
  <p>But nothing happens. The <a href="https://docs.mongodb.com/manual/reference/operator/update/pop/" rel="nofollow noreferrer">docs</a> makes this example:</p>
  
  <p><code>db.students.update( { _id: 1 }, { $pop: { scores: 1 } } )</code></p>
  
  <p>but it deletes an element of an array of one document in the db; in my case I need to pop the first entry of my db. Anyway, as I said the docs is not updated, because it uses <code>update</code> function that is deprecated.</p>
  
  <p>Do you know if is it possible to do what I need?</p>