In the first version of pogi the decision was to ignore the condition if the value was undefined in order for ease the use e.g.:
let query = {
powerfull: params.powerfull,
wise: params.wise
}
await pgdb.users.find(query);
would return a result if e.g. the form.wise
would be undefined. While this is comfortable
in many situation, it can cause critical issues e.g. for update
await pgdb.users.update({id:user.id}, {password});
would update all users password, in case of the user.id is undefined. (Although this can be mitigated
with the updateOne
function as well.) Still the best if no undefined value is allowed in the conditions.
Nevertheless to keep the compatibility, a parameter has been added to the QueryOptions
and the ConnectionOptions
: 'skipUndefined'. In the ConnectionOptions
it can be set to all
if needed (to keep the original behaviour). The value select
would allow undefined values for selects/count queries only but would be strict for update/deletes.
none
is the new default value, meaning undefined value considered as programming error and will throw an exception.
This setting can be specified on query level as well.