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

mongo shell has incorrect check for compatibility mode for write operations

    • Type: Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • ALL

      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            jon.rangel@mongodb.com Jon Rangel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: