#12211·mongoose

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

Author: Thomas-lmreCreated Aug 4, 2022Updated Jun 22, 2026
Labelsenhancementdiscussionbackwards-breaking

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 :

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