[SERVER-23579] WriteConcern can't be called on an object, must be new'ed Created: 06/Apr/16  Updated: 16/May/16  Resolved: 29/Apr/16

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: 3.3.6

Type: Bug Priority: Major - P3
Reporter: Matt Cotter Assignee: Matt Cotter
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Platforms 14 (05/13/16)
Participants:

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



 Comments   
Comment by Githook User [ 29/Apr/16 ]

Author:

{u'username': u'Machyne', u'name': u'Matt Cotter', u'email': u'matt.cotter@mongodb.com'}

Message: SERVER-23579 WriteConcern can be called on objects

Previously, to make a WriteConcer(

{j:true}

), it had to be "new"ed.
Now WriteConcern can be called on a write concern object.
Branch: master
https://github.com/mongodb/mongo/commit/02e0d1ee8f77ab6311d37e4ea29cacc706ff7e00

Generated at Thu Feb 08 04:03:48 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.