3

I want to create a text index on all of my fields in MongoDB. I know that it can be done like this:

db.collection.ensureIndex({ "$**": "text" },{ name: "TextIndex" })

But I want create this index in my Java program. I tried with this:

collection.createIndex(new BasicDBObject("$**","text"),newBasicDBObject("name","TextIndex"));

but it gave me this error: com.mongodb.MongoException: Can't canonicalize query: BadValue unknown operator: $**

I don't know what to do. I can see that others have asked the similar question but no one answered. Can any of you guys help me?

Thanks in advance.

3
  • 1
    Text search is a rather new feature. Are you maybe using an outdated version of the java driver? Or maybe even of MongoDB itself? Text search must be enabled through a config parameter in 2.4 and doesn't exist in prior versions. Commented Aug 15, 2014 at 9:02
  • Yes I know. Both my MongoDB and Java driver are their latest release. I can create an index on one field and it's working but I want to create index on all fields. Commented Aug 15, 2014 at 9:04
  • Oh, it seems that my Java Driver was not actually the latest release. I got the newest release and now it works like a charm. Commented Aug 15, 2014 at 11:08

1 Answer 1

2

Oops, it seems that my Java Driver was not actually the latest release. I got the newest release and now it works like a charm.

Always download your libs from the maven repos.

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.