title: Mongoose - Set TTL on MongoDB Document
body: <p>I am trying to set a TTL via mongoose when a document is created in MongoDB, but I'm not having any luck with any of my attempts. Latest version of mongoose is being used in my project and from what I can tell I've tried the most common answers here on SO and elsewhere online.</p>
  <p><strong>My Schema</strong></p>
  <pre><code>const mongoose = require('mongoose');
  
  const jobSchema = new mongoose.Schema(
      {
          positionTitle: {
              type: String,
          },
          description: {
              type: String,
          }
      });
  
  const Jobs = mongoose.model('job', jobSchema);
  
  module.exports = Jobs;
  
  </code></pre>
  <p>I have tried adding a createdAt with expires based on <a href="https://stackoverflow.com/questions/14597241/setting-expiry-time-for-a-collection-in-mongodb-using-mongoose">this</a> question answer:</p>
  <pre><code>const jobSchema = new mongoose.Schema({
      positionTitle: {
          type: String,
      },
      description: {
          type: String,
      },
      createdAt: { type: Date, expires: 3600 },
  });
  
  </code></pre>
  <p>Along with this option that's also in the same question to have createdAt be created automatically via timestamps:</p>
  <pre><code>const jobSchema = new mongoose.Schema(
      {
          positionTitle: {
              type: String,
          },
          description: {
              type: String,
          },
      },
      { timestamps: true }
  );
  </code></pre>
  <p>Trying variations of the following to set an index with timestamps defined:<br />
  <code>jobSchema.index({ createdAt: 1 }, { expires: 86400 });</code><br />
  <code>jobSchema.index({ createdAt: 1 }, { expires: '1 day' });</code><br />
  <code>jobSchema.index({ createdAt: 1 }, { expireAfterSeconds: 3600 });</code></p>
  <p>Regardless of which option I try, the document is removed after MongoDB's 60-second cycle when a createdAt field is set on the document. Would really love to know what I'm doing wrong.</p>