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

Remove FireAndForget and use magic values for "w" instead

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.7
    • Affects Version/s: 1.7
    • Component/s: None
    • Labels:
      None
    • Major Change

      After we had already finished implementing support for FireAndForget it was decided that FireAndForget was not an acceptable keyword after all. Instead, we are to use certain magic values for "w" to imply whether write concern is enabled or not, as follows:

      w meaning
      w=0 implies write concern is disabled
      w=1 implies write concern is enabled
      w=n n>1 implies write concern is enabled and provides the "w" value for the getLastError command

      At a low level these values result in the following getLastError commands being sent to the server:

      w getLastError command
      w=0 do not send a getLastError command
      w=1 send { getLastError : 1 }
      w=n n>1 send { getLastError : 1, w : n }

      see: http://www.mongodb.org/display/DOCS/getLastError+Command

      Interaction with getLastErrorDefaults

      A replica set can be configured with getLastErrorDefaults to be used when the driver sends a bare getLastError command with no arguments.

      See: http://docs.mongodb.org/manual/reference/replica-configuration/

      You override getLastErrorDefaults by providing some arguments to the getLastError command. This is done in the C# driver by assigning values to one or more properties of the new WriteConcern object (or setting the equivalent options in the connection string).

      For example, to override the getLastErrorDefaults with w=3 and journal=true you could either use this connection string:

      var connectionString = "mongodb://localhost/?w=3;journal=true";
      

      or this code:

      var writeConcern = new WriteConcern { W = 3, Journal = true };
      var clientSettings = new ClientSettings
      {
          Server = new MongoServerAddress("localhost"),
          WriteConcern = writeConcern
      };
      var client = new MongoClient(clientSettings);
      

      Either way results in the following getLastError command being sent to the server:

      { getLastError : 1, w : 3, journal : true }
      

      A consequence of this design is that it is impossible to send the following getLastError command:

      { getLastError : 1, w : 1 }
      

      because w=1 is a magic value that means to send a bare getLastError command instead.

      The result of this limitation is that it is impossible to override getLastErrorDefaults with a value of

      { w : 1 }

      .

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: