how to return documents which are contains the specific keywords in the keys from mongodb mlab in python flask [duplicate]

社会主义新天地 提交于 2019-12-20 06:04:09

问题


I have this collection in mongodb. my collection:

 {
"_id": "5ad2079019551a2108588add",
"brand_name": "MAZOLA LIZA"
"name":"pyd"
 }

{
"_id": "5ad2079019551a2108588adf",
"brand_name": "MAZcara"
"name":"rahul"  
}
{
"_id": "5ad2079019551a2108588agf",
"brand_name": jk LIZA"
"name":"qa" 
}

My desired output:

{
"_id": "5ad2079019551a2108588add",
"brand_name": "MAZOLA LIZA"
"name":"pyd"
 }

{
"_id": "5ad2079019551a2108588adf",
"brand_name": "MAZcara"
"name":"rahul"  
}

I am trying to get the documents which are contains MOZ in "brand_name"

I am using flask_pymongo for this.

ill send this MOZ using flask method. (method/MOZ)

my code is,

@app.route('/framework/<name>', methods=['GET'])
def get_one_framework(name):
    framework = mongo.db.offers
    for q in framework.find({"product": {"$regex":"*."+ name+".*"}}):
        print(q)

its not printing any records, but i have matching records

来源:https://stackoverflow.com/questions/49843914/how-to-return-documents-which-are-contains-the-specific-keywords-in-the-keys-fro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!