Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-15313

Capped collection documentation is not correct

      Capped collections documentation at https://www.mongodb.com/docs/manual/core/capped-collections/ specifies that

      "TTL indexes are not compatible with capped collections."

      However, the following tests with an empty database (i.e. no collections in the database when the test is done):

      {{> show collections
      > db.createCollection( "c",

      { capped: true, size: 100000 }

      )

      { "ok" : 1 }

      > db.c.isCapped()
      true
      > db.c.createIndex(

      { "date": 1 }

      ,

      { expireAfterSeconds: 3600 }

      )

      { "numIndexesBefore" : 1, "numIndexesAfter" : 2, "createdCollectionAutomatically" : false, "ok" : 1 }

      > db.c.getIndexes()
      [
      {
      "v" : 2,
      "key" :

      { "_id" : 1 }

      ,
      "name" : "id"
      },
      {
      "v" : 2,
      "key" :

      { "date" : 1 }

      ,
      "name" : "date_1",
      "expireAfterSeconds" : 3600
      }
      ]}}

      So, I understands the documentation is not correct or "compatibility" should be explained better (i.e. the index can be created but expiration on it is ignored).

       


      With MongoDB 7.0.0-rc4 and MongoDB 6.0.7

      Enterprise replset [direct: primary] test> db.createCollection( "c", {capped:true, size:100000})
      { ok: 1 }
      Enterprise replset [direct: primary] test> db.c.isCapped()
      true
      Enterprise replset [direct: primary] test> db.c.createIndex({"date":1},{expireAfterSeconds:3600})
      MongoServerError: Cannot create TTL index on a capped collection

      With MongoDB 5.0.18:

      test> db.createCollection( "c", {capped:true, size:100000})
      { ok: 1 }
      test> db.c.isCapped()
      true
      test> db.c.createIndex({"date":1},{expireAfterSeconds:3600})
      date_1

      Will update the 5.0 docs and backport to 4.4 and 4.2

            Assignee:
            nick.villahermosa@mongodb.com Nick Villahermosa
            Reporter:
            fermin.galanmarquez@telefonica.com Fermín Galán
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              41 weeks ago