WriteConcern can't be called on an object, must be new'ed

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • 3.3.6
    • Affects Version/s: None
    • Component/s: Shell
    • None
    • Fully Compatible
    • ALL
    • Platforms 14 (05/13/16)
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      When calling WriteConcern with new, it works as expected:

      > new WriteConcern({j: true})
      WriteConcern({ "j" : true })
      

      But without the new this fails:

      > WriteConcern({j: true})
      2016-04-06T15:43:44.271-0400 E QUERY    [thread1] Error: If the first arg is an Object then no additional args are allowed! :
      WriteConcern@src/mongo/shell/bulk_api.js:52:15
      WriteConcern@src/mongo/shell/bulk_api.js:45:1
      @(shell):1:1
      

      I think this is because when this isn't called with new, it recurses, always passing 3 arguments:

      if(!(this instanceof WriteConcern))
        return new WriteConcern(wValue, wTimeout, jValue);
      

      So we error here:

      if (typeof wValue == 'object') {
        if (arguments.length == 1)
          opts = Object.merge(wValue);
        else
          throw Error("If the first arg is an Object then no additional args are allowed!")
      }
      

            Assignee:
            Matt Cotter (Inactive)
            Reporter:
            Matt Cotter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: