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

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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 3.3.6
    • None
    • Shell
    • None
    • Fully Compatible
    • ALL
    • Platforms 14 (05/13/16)

    Description

      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!")
      }
      

      Attachments

        Activity

          People

            matt.cotter Matt Cotter
            matt.cotter Matt Cotter
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: