【问题标题】:Why does the $text query return no results? Mongodb为什么 $text 查询没有返回结果?蒙古数据库
【发布时间】:2022-06-22 18:07:38
【问题描述】:

我正在使用 Flask、WTFfroms、jinja 和 MongoDb 来制作一个简单的应用程序,用户可以在其中查询数据库并获得他正在寻找的结果。基本上,就像一个搜索引擎。

我为此使用了 $text 搜索,但由于某种原因我没有得到任何结果。

烧瓶应用

def results():
    form = SearchForm()
    if form.validate_on_submit():
        searched = request.form['searched']
        questions = list(db.find({"$text": {"$search": searched}}))

    return render_template("results.html", form=form, questions=questions, searched=searched)

神社样本



{% block body%}


{% for question in questions%}

<p>{{question}}</p>

{% endfor %}

{% endblock%}

【问题讨论】:

    标签: python mongodb flask mongodb-query jinja2


    【解决方案1】:

    在我看来,您缺少为集合中的字段创建索引 参考这里: https://www.mongodb.com/docs/manual/indexes/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-24
      • 1970-01-01
      • 2011-11-07
      • 2022-08-18
      • 2021-12-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多