Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-841

Allow AutoIndexId and Capped to be set to false as well as true in CollectionOptionsBuilder

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: 1.8.3
    • Fix Version/s: 1.9
    • Component/s: None
    • Labels:
      None

      Description

      This native Mongo shell command works fine

      db.createCollection("noautoid", { autoIndexId: false })

      i.e. a collection created with no index on `_id`.

      But I cannot achieve the same using

      CollectionOptionsBuilder.SetAutoIndexId(false)

      The index is always created.

      I took a look at the code:

      MongoDB.Driver\Builders\CollectionOptionsBuilder.cs(104):

              public CollectionOptionsBuilder SetAutoIndexId(bool value)
              {
                  if (value)
                  {
                      _document["autoIndexId"] = value;
                  }
                  else
                  {
                      _document.Remove("autoIndexId");
                  }
                  return this;
              }

      It looks like `SetAutoIndexId(false)` makes the option removed, so that the
      default is used which is presumably `true`.

      Perhaps the correct code would be

              public CollectionOptionsBuilder SetAutoIndexId(bool value)
              {
                  if (value)
                  {
                      _document["autoIndexId"] = value;
                  }
                  return this;
              }

      which adds the option `

      { autoIndexId: false }

      ` explicitly, like the Mongo shell
      command does and works as desired.

        Attachments

          Activity

            People

            Assignee:
            rstam Robert Stam
            Reporter:
            nightroman Roman Kuzmin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: