0

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 Answer 1

2

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().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.