通配符文本索引和继承的架构 [英] Wildcard Text Index and inherited schemas

查看:78
本文介绍了通配符文本索引和继承的架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用discriminatorKey有1个根模式和4个继承的模式 http://mongoosejs.com/docs/discriminators.html

I have 1 root schema and 4 inherited schemas using a discriminatorKey http://mongoosejs.com/docs/discriminators.html

在这种情况下,我不清楚是否可以使用通配符文本索引.目的是独立地索引每个继承模式的所有字符串字段. https://docs.mongodb.org/manual/core/index-text/

In this scenario I'm not clear if I can use a wild card text index. The purpose is to index all the string fields of each inherited schema independently. https://docs.mongodb.org/manual/core/index-text/

编辑 在我的猫鼬根架构上添加此myRootSchema.index({ "_type": 1, "$**": "text" });,当我尝试查询时出现此错误.我也应该在继承的模式上重复这一点吗?

EDIT Adding this myRootSchema.index({ "_type": 1, "$**": "text" }); on my mongoose root schema I get this error when I try to query. Should I repeat this on the inherited schemas too?

{
"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)
    });

推荐答案

要有效利用

To efficiently utilize a wildcard index with inherited schemas, you'd want to use a compound text index using the kind discriminator field as the leading field in the index:

{ kind: 1, "$**": "text" }

这篇关于通配符文本索引和继承的架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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