MongoDB text index for all fields using Java
I want to create a text index for all my fields in MongoDB. I know it can be done like this:
db.collection.ensureIndex({ "$**": "text" },{ name: "TextIndex" })
But I want to create this index in my Java program. I've 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 do not know what to do. I see others have asked a similar question, but no one has answered. Can any of you help me?
Thanks in advance.
+3
source to share