in my database, there are two companies with same name.
[
{
"name": "samsung",
"store_code": "34d"
},
{
"name": "lg",
"store_code": "333"
},
{
"name": "lg",
"store_code": "3511"
}
]
like this..
my question is, I juse made my python function to get store information by name.
that looks like this..
async def fetch_store_by_name(store_name):
document = collection.find_one({"name":store_name})
return document
and I can only get the first lg company's information. how can I get both informations of lg company from my mongodb?
CodePudding user response:
Use find
instead of find_one
.
https://www.w3schools.com/python/python_mongodb_find.asp
CodePudding user response:
I assumed you're using pymongo
, just change find_one
to find
method. Like this:
async def fetch_store_by_name(store_name):
document = collection.find({"name":store_name})
return document
Here some documentation : https://pymongo.readthedocs.io/en/stable/tutorial.html#querying-for-more-than-one-document