Model.exists() should return a query instead of a promise
See original GitHub issueRe: #8075 , Model.exists()
is very inconsistent with other helper functions.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@AbdelrahmanHafez actually
exists()
will still trigger pre(‘findOne’) hooks. Unless you happen to change query op before executing.@felixveysseyre there is an options parameter to
exists()
, you should be able to doModel.exists(filter, { session })
. Does that not work for you?