Using the following code with perfect results, pulling records from Mongo.
@app.route('/search-all/', methods=['GET', 'POST'])
def search_all():
query = request.form.get("SearchBox")
try:
for x in db['mongo-moviedb'].find({"Films.Title" : f"{query}" }, {"Films.$": 1}):
title = x["Films"][0]["Title"]
genre = x["Films"][0]["Genre"]
cast = x["Films"][0]["Actors"]
plot = x["Films"][0]["Plot"]
return render_template('Date-Night.html', title=title,genre=genre,cast=cast,plot=plot)
except (RuntimeError, TypeError, NameError):
error = 'Not found.'
return render_template('Date-Night.html', error = error)
The problem is it won't pull partial matches. I can get exact matches or the error prompt. I've tried using $regex and /like/ in the find() function to no avail. Haven't been able to find anything that returns a result that only partially matches the record. Also it has to include the 'query' variable pulled from form input.
Ex: 'Star' would return Star Wars, Starman, Wish Upon a Star....etc.
Thanks.
Example: