0

My friend's app was designed to use MongoDB indexes. Everything was fine while he was developing locally, but once he moved his code to the hosting provider, the code fails:

db.createIndex('collections', {title:"text", description:"text"}, function(err, indexName) {
    console.log("8. index name: " + indexName);
});

The error message is "index creation failed"

Provider says this is because they do not upgrade MongoDB to 2.6, their version is 2.4 and they have no plans to upgrade. I looked into MongoDB website, but the Indexes section does not mention that indexes are not available until 2.6. It only says that 2.6 has some extra features. So what's going on here, something wrong with this code or is really MongoDB not supporting indexes until 2.6, how could that be, or we are doing something wrong, what is the option to have a fast search with MongoDB 2.4?

1

2 Answers 2

2

as Lix said, createIndex is deprecated. You should use ensureIndex instead:

collection.ensureIndex({title:"text", description:"text"}, function(err, indexName) {
  //handle error and check index name
})

please remember, that this is compound index, not two seperate indexes created at once

more info here: link
info about indexes in nodejs (i assumue You use nodejs, as You used callback:) link2

EDIT

There is info in docs stating that " In MongoDB 2.4, you need to enable the text search feature manually to create text indexes and perform text search."
link and source: indexes

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

Comments

0

There is a bit of confusion here. MongoDB 2.4.* does have indexes; indexing is not of feature of 2.6 -- so thats not the problem. I would try two things: first, try to create the index manually from the mongo shell -- perhaps the error message is more meaningful. If that doesnt help, ask the provider to see the mongod log file -- it will definitely show your index creation attempt operation and, hopefully, why it had failed. Finally, it might be failing because text search might not have been enabled? The MongoDB 2.4 documentation mentions "textSearchEnabled" command line parameter that needs to be set to true when launching mongod process

Hope this helps.

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.