[SERVER-26623] call deleteOne with an array in shell Created: 13/Oct/16  Updated: 16/Nov/21  Resolved: 07/Feb/17

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 3.2.10
Fix Version/s: 3.5.3

Type: Bug Priority: Minor - P4
Reporter: Jaap Taal Assignee: Jonathan Reams
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

macOSX (installed with brew)


Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Operating System: OS X
Sprint: Platforms 2016-10-31, Platforms 2017-02-13
Participants:
Linked BF Score: 0

 Description   

db.mycoll.deleteOne([])
2016-10-13T22:51:09.884+0200 E QUERY    [thread1] TypeError: err.hasWriteErrors is not a function :
DBCollection.prototype.deleteOne@src/mongo/shell/crud_api.js:328:13
@(shell):1:1

I accidentally ran deleteOne with an array. When you do that you should get an error, but I think this is an internal bug in the shell.

BTW: I couldn't find the right project for the shell, so I filed it under tools.



 Comments   
Comment by Githook User [ 09/Feb/17 ]

Author:

{u'username': u'jbreams', u'name': u'Jonathan Reams', u'email': u'jbreams@mongodb.com'}

Message: SERVER-26623 Check whether error is BulkWriteError before unpacking it
Branch: master
https://github.com/mongodb/mongo/commit/1b49f7f0e3d72662ddf81d7c3ed5254d874a0673

Comment by Githook User [ 07/Feb/17 ]

Author:

{u'username': u'ksuarz', u'name': u'Kyle Suarez', u'email': u'kyle.suarez@mongodb.com'}

Message: SERVER-26623 fix lint
Branch: master
https://github.com/mongodb/mongo/commit/2c1cce8c3b1920a307a376bcc3b91edb79cf110a

Comment by Githook User [ 07/Feb/17 ]

Author:

{u'username': u'jbreams', u'name': u'Jonathan Reams', u'email': u'jbreams@mongodb.com'}

Message: SERVER-26623 Propagate bulk api write errors in shell CRUD api
Branch: master
https://github.com/mongodb/mongo/commit/14c608a79b22876bfed4769d9a0c3eb47e8f8d96

Comment by Jonathan Reams [ 02/Feb/17 ]

I think the problem here is that when we execute a bulk api it checks whether there are any errors and throws them as a BulkWriteError, which is just a fancy error - so by the time it reaches this code that I think is meant to convert an array of errors its already a single Error. I think we should just remove that try/catch block in all the single write APIs and let the bulk write API format the errors they way it wants.

Comment by Jaap Taal [ 27/Oct/16 ]

If it's not fixable, this issue should be closed of course.

Comment by Jaap Taal [ 27/Oct/16 ]

Fair enough, it's just that I tought that

TypeError: err.hasWriteErrors is not a function

was an error that usually indcates some precondition for a piece of code is violated. I was guessing it should be possible to raise a more specific error, because err is some internal variable.

Comment by Mira Carey [ 26/Oct/16 ]

jaap@q42.nl,

Unfortunately, the shell lacks the kind of pervasive argument checking necessary to validate that all forms of input are sane. In this particular case, you're experiencing JavaScript's inclination to treat Array's as Objects, and that the filter argument to deleteOne is a generic object, rather than some more formal type. Thus, [] becomes {}, which becomes deleteOne({}).

Given that existing code out in the wild requires only that filter be an object (rather than having a specific prototype/constructor) it would be a backwards breaking change for us to begin constraining that space to specifically plain objects (or to one of our choosing). So while I'm sympathetic that array is clearly not a reasonable option, closing that loophole would leave:

  • db.mycoll.deleteOne(mySpecialObjectType)
  • db.mycoll.deleteOne( { didnt_mean_to_pass_this : 1}

    )

  • db.mycoll.deleteOne(/regex/)
  • etc.

Let alone equivalent problems across the entire shell javascript api.

If we ever end up writing a new shell, with a new api, I'd be interested in a vastly more type-constrained interface. Unfortunately, that's not something that we can tackle at this time in the current shell codebase.

Comment by Kelsey Schubert [ 13/Oct/16 ]

Hi q42jaap,

Thank you for the report. I've assigned this issue to the Platforms Team to continue to investigate. Please continue to watch this ticket for updates.

Kind regards,
Thomas

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