balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.83k stars 1.95k forks source link

Find, Destroy or Update methods ignore undefined type attributes #4639

Open Josebaseba opened 7 years ago

Josebaseba commented 7 years ago

Waterline version: 0.13.0-rc11 Node version: 4.5 NPM version: 2.15.9 Operating system: MacOs


Hi guys, I found an issue that I'm not sure if it's a bug or something that you have considered. If you do something like this:

User.update({id: undefined}, {name: 'joe'}).exec()

This is gonna update ALL the users in the database, because the mongo query is gonna be something like this {}. The same thing happens with find/destroy methods.

So imagine that in your code you don't realize data X value is undefined and you lauch a destroy against it, you'll end up dropping all the collection with no clue about what just happened.

Thanks for your time.

eashaw commented 3 years ago

Thanks for the heads up @himankpathak, we've updated our migration docs to include this information.

latifasaee commented 2 years ago

@eashaw I'm also facing this error with mysql db, any help code: 'E_INVALID_CRITERIA', details: 'CannotupdateOne()without specifying a more specificwhereclause (the providedwhereclause,{}, is too broad).' },

eashaw commented 2 years ago

Hi @latifasaee, are you using updateOne() with undefined criteria?