Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model.exists() should return a query instead of a promise #8097

Closed
vkarpov15 opened this issue Aug 23, 2019 · 7 comments
Closed

Model.exists() should return a query instead of a promise #8097

vkarpov15 opened this issue Aug 23, 2019 · 7 comments

Comments

@vkarpov15
Copy link
Collaborator

Re: #8075 , Model.exists() is very inconsistent with other helper functions.

@vkarpov15 vkarpov15 added this to the 5.x Unprioritized milestone Aug 23, 2019
@felixveysseyre
Copy link

I cannot agree more with @vkarpov15

With current implementation, there is no way to use exists in a transaction context 😭

@vkarpov15
Copy link
Collaborator Author

@felixveysseyre there is an options parameter to exists(), you should be able to do Model.exists(filter, { session }). Does that not work for you?

@felixveysseyre
Copy link

felixveysseyre commented Dec 20, 2019

@vkarpov15 Thanks for your answer 🙃

Looking into the sources, I have been able to find the options parameters you are talking about.

I've been tricked by the outdated documentation and the wrong types 😭

@vkarpov15
Copy link
Collaborator Author

Making a note of this for #8108

vkarpov15 added a commit that referenced this issue Mar 23, 2020
…romise, and return doc or null, rather than true/false

Fix #8097
@AbdelrahmanHafez
Copy link
Collaborator

@vkarpov15
This will make it so that Model.exists(...) won't trigger pre-findOne hooks, correct?

If so, this should fix #8739

@AbdelrahmanHafez
Copy link
Collaborator

Should revert #8764 once this is released.

@vkarpov15
Copy link
Collaborator Author

@AbdelrahmanHafez actually exists() will still trigger pre('findOne') hooks. Unless you happen to change query op before executing.

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

No branches or pull requests

3 participants