question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
vkarpov15commented, Apr 10, 2020

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

1reaction
vkarpov15commented, Dec 20, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mongoose v6.8.1: Promises
Mongoose async operations, like .save() and queries, return thenables. This means that you can do things like MyModel.findOne({}).then() and await MyModel.
Read more >
Mongoose - Create document if not exists, otherwise, update
The new option returns the newly created document(if a new document is created). Use it like this: var query = {}, update =...
Read more >
.findOne(undefined) returns first item in the database instead ...
I would suppose User.findOne() will return one record without any conditions (if exists).
Read more >
Resolvers - Apollo GraphQL Docs
Return values ; Promise. Resolvers can be asynchronous and perform async actions, such as fetching from a database or back-end API. To support...
Read more >
Promises and Callbacks — Node.js - MongoDB
Certain methods in the driver such as find() return a Cursor instead of a Promise. To determine what type each method returns, refer...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found