【问题标题】:Mongo DB Search QueryMongoDB搜索查询
【发布时间】:2018-07-11 08:32:25
【问题描述】:

我在我的程序中编写了以下代码,但它将每个单词都视为单独的关键字......我希望将整个句子仅视为一个关键字。

var typed =typing.substring(4,typing.indexOf(":")-3)
db.collection('Question').find({$text:{$search : typed }},{projection:{_id: 0, Question:1}}).toArray(function(err, result) 
    {
        if(err)
            console.log(err);
        console.log(result);
    })

$text 是我的数据库表上的索引名称。

【问题讨论】:

    标签: mongodb find


    【解决方案1】:

    您可以像这样简单地引用您的字符串以使 MongoDB 搜索文字文本:

    var typed = '\"' + typing.substring(4,typing.indexOf(":")-3) + '\"'
    

    另见documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-19
      • 2022-10-05
      • 2021-12-19
      • 2015-06-29
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多