复合索引MongoDB

时间:2019-11-26 10:26:21

标签: mongodb

我使用的是MongoDb服务器版本:4.2.0。 我有复合索引MongoDB:

db.fop.createIndex( { "id":1, "ADDRESS": "text"})

有效:

db.fop.find({"id":{$in:[1]},$text: {$search: "AnyTextSearch"}}, {score: {$meta: "textScore"}}).sort({score:{$meta:"textScore"}})

这不起作用:

db.fop.find({"id":{$in:[1,2]},$text: {$search: "AnyTextSearch"}}, {score: {$meta: "textScore"}}).sort({score:{$meta:"textScore"}})

我得到一个错误:

Error: error: {
    "ok" : 0,
    "errmsg" : "error processing query: ns=osint.fopTree: $and\n    id $in [ 1.0 2.0 ]\n    TEXT : query=AnyTextSearch, language=english, caseSensitive=0, diacriticSensitive=0, tag=NULL\nSort: { score: { $meta: \"textScore\" } }\nProj: { score: { $meta: \"textScore\" } }\n planner returned error :: caused by :: failed to use text index to satisfy $text query (if text index is compound, are equality predicates given for all prefix fields?)",
    "code" : 2,
    "codeName" : "BadValue"}

如何提出正确的请求?

0 个答案:

没有答案