Rollback the implementation of .exists() method to be syntactically consistent (+ add similar method with correct naming)
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the feature has not already been requested
Feature Proposal
Description
The exists method in common frameworks and implementation implies the same thing : a boolean (or promise that resolve to a boolean).
Changing the meaning of this function can be extremely misleading for everyone that will make assumptions, this change produce a breaking change (even if the value is "truthy").
Consider the snippet bellow, even if code like this may be extremely rare, its remains inconsistent syntactically :
const exists = await Model.exists({});
if (exists) {} // works
if (exists === false) {} // never trigger
if (exists === true) {} // never triggerProposition
I know the functionality provided by the new implementation is wanted, so bellow my proposition :
- revert the changes to this signature (as of
5.13.Xversion) :
prototype.exists({}): Promise<boolean>- add a method to keep the
existsfunctionality :
prototype.findOneId({}) : Promise<{_id: ObjectId}|null>Motivation
Keeping code consistent, understandable for anyone, with no misleading syntax or behaviours
Someone that doesn't know mongoose, should be able to read the code and understand it without documentation.
Example
No response
edit: typo
Source: Automattic/mongoose