1

discriminatorKey http://mongoosejs.com/docs/discriminators.htmlを使用して、1 つのルート スキーマと 4 つの継承スキーマがあります 。

このシナリオでは、ワイルド カード テキスト インデックスを使用できるかどうかはわかりません。目的は、継承された各スキーマのすべての文字列フィールドを個別にインデックス化することです。 https://docs.mongodb.org/manual/core/index-text/

EDIT これを私のマングースルートスキーマに追加する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)
    });
4

1 に答える 1

1

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" }
于 2016-03-09T18:24:46.753 に答える