Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-5503

All capped collections are implicitly limited to 2^31 - 1 documents

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.0.4, 2.1.0
    • Component/s: None
    • None
    • ALL

      If you attempt to create a capped collection with a maximum number of documents greater than 2^31 - 1, Mongo silently lowers this to exactly 2^31-1:

      > db.runCommand({create: "cappedWithMax", capped: true, size: 10000000, max: 4294967296})
      { "ok" : 1 }
      > db.cappedWithMax.stats().max
      2147483647
      

      If you leave the "max" field out of the creation command, you still get 2^31 - 1 as max:

      > db.runCommand({create: "cappedWithoutMax", capped: true, size: 10000000})
      { "ok" : 1 }
      > db.cappedWithoutMax.stats().max
      2147483647
      

      This seems to be due to this section of _userCreateNS in pdfile.cpp (at line 259 on current master):

              if( options["capped"].trueValue() ) {
                  newCapped = true;
                  BSONElement e = options.getField("max");
                  if ( e.isNumber() ) {
                      mx = e.numberInt();
                  }
              }
      

      I would expect that the range of valid values for max should be either a long (2^63 - 1), unsigned long (2 ^ 64 - 1); or alternately that not specifying max leaves the number of documents unbounded.

            Assignee:
            Unassigned Unassigned
            Reporter:
            dcrosta Daniel Crosta
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: