'How do I search a mongodb database for hashed api keys

I'm in the process of creating an API, when a user signs up they're given an API key that is hashed using bcrypt-js before it is saved in their user model in the mongodb database. They then use this key to make requests to the API endpoint like this...

GET https://api.example.com/v1/events/api_key=hjlh6y727h2lkj4k5

What I don't understand is, how do I find this API key in the database if all the keys are hashed before they're stored? I can't just search for the key using the following mongodb query, so how would I match the api_key sent in the request with the correct user model?

User.findOne({ api_key: API_KEY_PROVIDED })


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source