New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collection.remove() should throw an error when used with an empty array, instead of removing all items #4804
Comments
But in doc we can find:
Also, I think beginners must know, that better use some "remove" flag instead of deleting record. |
@jagi 👍 absolutely. Let's say this burned me just now ... |
@osv, for a less seasoned js and mongo programmer, it feels idiomatic to pass an array of ids to a query, and it's really easy to do this if you are not that versed in the mongo selector query style. |
I'm not sure if it's idiomatic or not, but I agree that Mongo should probably throw an error instead of silently accepting the wrong type of argument, worse still if that results in deleting all items from the database. |
Woo! Thanks @stubailo! =) |
@stubailo, would it be possible at all to include me in the PR when you get around to doing this? Just curious to see how this would be implemented. |
@stubailo, looks great thanks! ^_^ |
Fix #4804 and throw error when Mongo selector is array
So, with javascript it is really easy to inadvertently pass an array object
Collection.remove(array)
as the selector, and if that array is the empty array, it deletes all documents in that collection!Collection.remove()
should throw an error if passed an array (like it does in mongo!) or at the very least not delete the whole collection if an empty array gets passed as the selector. This seems like a very dangerous query loophole that could easily burn beginners of Meteor.The text was updated successfully, but these errors were encountered: