Mongodb错误“无法使用文本索引来满足$ text查询". [英] Mongodb error "failed to use text index to satisfy $text query"

查看:351
本文介绍了Mongodb错误“无法使用文本索引来满足$ text查询".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用全文搜索.以这种方式设置索引

I'm trying to use the fulltext search. Setting the index in this way

myRootSchema.index({ "_type": 1, "$**": "text" }); 

其中_type是discriminatorKey,而myRootSchema是4个继承模式的父模式.

where _type is a discriminatorKey and myRootSchema is the father schema of 4 inherited schemas.

我收到此错误

{
"name": "MongoError",
"message": "error processing query: ns=MYDB.caseNotesTree: TEXT : query=title, language=english, caseSensitive=0, diacriticSensitive=0, tag=NULL\nSort: {}\nProj: {}\n planner returned error: failed to use text index to satisfy $text query (if text index is compound, are equality predicates given for all prefix fields?)",
"waitedMS": 0,
"ok": 0,
"errmsg": "error processing query: ns=MYDB.caseNotesTree: TEXT : query=title, language=english, caseSensitive=0, diacriticSensitive=0, tag=NULL\nSort: {}\nProj: {}\n planner returned error: failed to use text index to satisfy $text query (if text index is compound, are equality predicates given for all prefix fields?)",
"code": 2
}

尝试此查询

Model
    .find(
        { $text : { $search :req.query.q } }

    )
    .exec(function(err, data) {
        if(err)res.json(err)
        res.json(data)
    });

如建议的那样,我应该在查询中设置_type字段,但是_type是'autofilled',因为它是一个区分符.具有单个_type的查询有效,但我不需要这样做,我必须查询4个继承的模型. 我什至尝试了$ or,但不会出现相同的错误.

as suggested, I should set the _type field in the query, but the _type is 'autofilled' since is a discriminator. A query with a single _type works, but I don't need that, I have to query 4 inherited models. I even tried an $or, doesn't work with the same error.

Model
    .find(
        {   $or: [ { _type: 'childA' },
            { _type: 'childB' },
            { _type: 'childC' },
            { _type: 'childD' }
        ], $text : { $search :req.query.q } }

    )
    .exec(function(err, data) {
        if(err)console.log(err)
        res.json(data)
    });

推荐答案

错误消息显示如果文本索引是复合的,是否为所有前缀字段都提供相等谓词?".这意味着,在您的查询中,还要求提供类型.您的查询不会执行此操作,因为它仅使用索引的$text部分,而不使用索引的type部分.

The error messages says "if text index is compound, are equality predicates given for all prefix fields?". That means, that in your query you are required to supply type as well. Your query does not do that, as it only uses the $text part, but not the type part of the index.

这篇关于Mongodb错误“无法使用文本索引来满足$ text查询".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆