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

createIndex -- a single index may be both Partial and TTL

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • # Replies:
      0
    • Last comment by Customer:
      true
    • Story Points:
      0.1

      Description

      Description

      It appears that – at least on 4.0.5 – indexes can be both Partial and TTL

      The documentation seems rather silent on this point.  Perhaps it is not meant to work?

      Example

      The documentation is not entirely clear on the subject of creating indexes that are *both "partial" and "TTL", so I have tested this myself in a version 4.0.5 mongod. I found that I could indeed create an index that combined the attributes of "TTL Index" and "Partial Index", and that it did indeed expire only documents matching the partialFilterExpression defined on the index.

      As an example, on the collection test.foo, I created an index:

      db.foo.createIndex({F:1}, {partialFilterExpression: {D: 1}, expireAfterSeconds: 10})

      {{}}

      and then inserted two documents into the collection:
      {{}}

      { "_id" : ObjectId("5c8188656c5c4825af60c90e"), "F" : ISODate("2019-03-07T20:59:18.428Z"), "D" : 3 }
       { "_id" : ObjectId("5c81886c6c5c4825af60c90f"), "F" : ISODate("2019-03-07T20:59:18.428Z"), "D" : 1 }

      {{}}

      Here, the index will expire documents when the F field contains a Date more than 10 seconds old, but we intend it to expire only those documents where D = 1 – the document with D = 3 should be left untouched.

      Waiting for about a minute for the index to activate, this is the data left in the collection:
      {{}}

      { "_id" : ObjectId("5c8188656c5c4825af60c90e"), "F" : ISODate("2019-03-07T20:59:18.428Z"), "D" : 3 }

      {{}}

      The index has expired the data we wanted expired, and only that data

      Scope of changes

      • ToDo: Explore application of partial property on other index properties or types
      • Update documentation for partial indexes to explicitly state it's applicability to constraining other index properties or types.

       

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              mark.brinsmead Mark Brinsmead
              Participants:
              Last commenter:
              Ravind Kumar
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Days since reply:
                23 weeks, 6 days ago
                Date of 1st Reply: