我使用discriminatorKey有1个根模式和4个继承模式 http://mongoosejs.com/docs/discriminators.html
在这种情况下,我不清楚我是否可以使用通配符文本索引。目的是独立地索引每个继承的模式的所有字符串字段。 https://docs.mongodb.org/manual/core/index-text/
修改
在我的mongoose根模式上添加此myRootSchema.index({ "_type": 1, "$**": "text" });
我在尝试查询时遇到此错误。我是否应该在继承的模式上重复这个?
{
"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)
});
答案 0 :(得分:1)
要有效地利用具有继承模式的wildcard index,您需要使用compound text index kind
鉴别器字段作为索引中的前导字段:
{ kind: 1, "$**": "text" }