Skip to content

Rollback the implementation of .exists() method to be syntactically consistent (+ add similar method with correct naming)聽#12211

Description

@Thomas-lmre

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 trigger

Proposition

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.X version) :
prototype.exists({}): Promise<boolean>
  • add a method to keep the exists functionality :
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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backwards-breakingdiscussionIf you have any thoughts or comments on this issue, please share them!enhancementThis issue is a user-facing general improvement that doesn't fix a bug or add a new feature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions