Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-1126

db.collection.totalSize concatenates instead of adds

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.2.2
    • Affects Version/s: 1.1.9
    • Component/s: Shell API
    • Labels:
      None
    • Environment:
      mongosh 1.1.9, macOS 12.2.1 on M1/arm64
    • 1
    • Not Needed
    • Iteration Utica, Iteration Versailles

      Problem Statement/Rationale

      Calling db.collection.totalSize() on a collection that's around 1.7 terabytes returns a size of about 200 zettabytes. This seems to be because it's concatenating the values of storageSize and totalIndexSize as strings instead of adding them together.

      Steps to Reproduce

      1. Have a collection that's large enough that storageSize returns a Long.
      2. Call db.collection.totalSize() on the collection

      Expected Results

      I expect the value to be storageSize and totalIndexSize added together as integers.

      Actual Results

      The number returned is far too large, and equal to storageSize and totalIndexSize concatenated as strings, instead of added together.

      my-db> db["my-collection"].totalSize()
      173274991001610559533056
      my-db> db["my-collection"].storageSize()
      Long("1732749910016")
      my-db> db["my-collection"].totalIndexSize()
      10559533056

      Additional Notes

      This seems to be because the code does storageSize + totalIndexSize, and adding a Long to an integer (or a Long to a Long) concatenates them instead of adding them.

      my-db> Long("1") + 1
      11
      my-db> Long("1") + Long("1")
      11
      my-db> 1 + Long("1")
      11
      my-db> 1 + 1
      2
      

            Assignee:
            leonardo.rossi@mongodb.com Leonardo Rossi (Inactive)
            Reporter:
            sarah@circleci.com Sarah Hodne
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: