mongo db text search error no text index for

只谈情不闲聊 提交于 2019-12-20 07:14:57

问题


I'm trying to use mongo db text search but I get the following msg error - no text index for Although you can see that there are text indexes in db.items. what's the problem? what is the command in mongoose?

> db.items.getIndexes()
[
    {
        "v" : 1,
        "key" : {
            "_id" : 1
        },
        "ns" : "db.items",
        "name" : "_id_"
    },
    {
        "v" : 1,
        "key" : {
            "type" : "text",
            "color" : "text",
            "category_A" : "text",
            "category_B" : "text",
            "category_C" : "text"
        },
        "ns" : "db.items",
        "name" : "type_text_color_text_category_A_text_category_B_text_category_C_text",
        "sparse" : false,
        "background" : false
    }
]
> db.items.runCommand( "text",{search:"D"})
{ "ok" : 0, "errmsg" : "no text index for: db.items" }

回答1:


First, did you start mongo with textSearchEnabled=true (see Enable text search)?

If you're using a config file (e.g. /etc/mongodb.conf) the correct line should be:

setParameter = textSearchEnabled=true

Second, your index looks like a regular index rather than text. Please post the command you used.


If you want to test the text index function, try the following:

Drop your current index (it may interfere with the new one you'll create)

db.items.dropIndex("type_text_color_text_category_A_text_category_B_text_category_C_text")

and create a new one

db.items.ensureIndex( {type:"text"}, {unique: false, name: "type_index"})

and then try the search again.

You may also need to run db.items.reIndex().



来源:https://stackoverflow.com/questions/15989297/mongo-db-text-search-error-no-text-index-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!