mongodump/mongorestore loses raw timeseries indexes (should clone with rawData: true)

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: mongodump, mongorestore
    • None
    • Tools and Replicator
    • 4

      Context

      For timeseries collections, there are two representations for indexes:

      • Logical, user visible representation
      • Physical, internal bucketed indexes, accessible with {rawData: true}.

       

      For example:

      > db.createCollection("myts", {timeseries:{timeField:'t'}})
      > db.myts.createIndex({t: 1})
      > db.runCommand({listIndexes: "myts"}).cursor.firstBatch.map(i => i.key)
      [ { t: 1 } ]
      > db.runCommand({listIndexes: "myts", rawData: true}).cursor.firstBatch.map(i => i.key)
      [ {'control.min.t': 1, 'control.max.t': 1 } ]
      

       

      A logical representation always has a physical representation, but the opposite is not always true. For example consider the physical index {control.closed: 1, control.min.t: 1}:

      > db.myts.createIndex({"control.closed": 1, "control.min.t": 1}, {rawData: true})
      > db.runCommand({listIndexes: "myts"}).cursor.firstBatch.map(i => i.key)
      [ { t: 1 } ]
      > db.runCommand({listIndexes: "myts", rawData: true}).cursor.firstBatch.map(i => i.key)
      [
         { 'control.min.t': 1, 'control.max.t': 1 }
         { 'control.closed': 1, 'control.min.t': 1 }
      ]

      As we can see, logical listIndexes without rawData:true just omits the index.

      Problem Statement/Rationale

      Currently mongodump/mongorestore lists and recreate the indexes in logical format. So in the case above, the {control.closed: 1, control.min.t: 1} is absent from the dump and is lost after a restore:

      > db.runCommand({listIndexes: "myts", rawData: true}).cursor.firstBatch.map(i => i.key)
      [
        { 'control.min.t': 1, 'control.max.t': 1 }
        { 'control.closed': 1, 'control.min.t': 1 }
      ]
      > mongodump
      > db.dropDatabase()
      > mongorestore
      > db.runCommand({listIndexes: "myts", rawData: true}).cursor.firstBatch.map(i => i.key)
      [
        { 'control.min.t': 1, 'control.max.t': 1 }
      ] 

       

      Impact

      Generally users should never directly create indexes using rawData:true like the above.
      However, they have historically been used internally as a workaround for performance issues, so they may exist in customer clusters.

      Proposed fix

      mongodump and mongorestore should call listIndexes/createIndexes with rawData: true so that timeseries indexes that do not have a logical representation are correctly preserved by a dump+restore.

      Affected versions

      • The examples above use the v9.0+ viewless timeseries syntax but this problem also exists in older versions with legacy timeseries, This is a day-0 issue since timeseries was released in MongoDB 5.0.

            Assignee:
            Unassigned
            Reporter:
            Joan Bruguera Micó
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: