how to return documents which are contains the spe

2019-03-04 10:22发布

问题:

This question already has an answer here:

  • Performing regex Queries with pymongo 5 answers
  • MongoDB/PyMongo: how to 'escape' parameters in regex search? 2 answers

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