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

mongo shell has incorrect check for compatibility mode for write operations

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Cannot Reproduce
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Operating System:
      ALL

      Description

      In 2.6+ versions of the mongo shell, there is the following check in the insert(), update() and remove() methods on the collection object:

         if ( this.getMongo().writeMode() != "legacy" ) {
              // use write commands
          else {
              // use legacy write op, followed by getLastError
          }
      

      The problem is, with versions of the server prior to 2.6 this.getMongo().writeMode() returns "compatibility", NOT "legacy", so the 'else' block in the above code is never executed.

      The impact is that the write concern passed in by the caller is not respected, since getLastError is not called.

      A workaround is for the user is to make an explicit getLastError call (on the same line, if running an interactive shell):

      e.g.

      db.foo.remove({_id:1}); db.runCommand({getLastError:1, w:2})
      

      The above code works with both 2.4 and 2.6+ versions of the server.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: