I am creating a small application, where my user are hosted into a MongoDB server. My application is in Python, so I'm using the pymongo driver.
The structure of my users looks like this :
{
"id": "1",
"username": "username",
"mail": "mail@mail.com",
}
On my API, I want to have a GET route that look like this :
http://api.lan/api/v1/users/{user_info}
Where user_info can be any of the following MongoDB document field: id, username, mail.
Today, with using the pymongo driver, I'm only able to search in my collections by searching on a specific field, like so :
self._users.find_one("username": "username")
But I would love to be able to search without having to tell the find_one()
method about the username field, and just to search in the users
collection any document where a field is equal to a given string.
If someone knows how I can achieve that, I would appreciate !
Thanks for your help :)