使用Java在所有字段上的MongoDB文本索引 [英] MongoDB Text Index on all Fields using Java

查看:243
本文介绍了使用Java在所有字段上的MongoDB文本索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MongoDB中的所有字段上创建一个文本索引.我知道可以这样做:

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" })

但是我想在我的Java程序中创建此索引.我尝试了这个:

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

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

但是它给了我这个错误: com.mongodb.MongoException: Can't canonicalize query: BadValue unknown operator: $**

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?

谢谢.

推荐答案

糟糕,看来我的Java驱动程序实际上不是最新版本.我得到了最新的发行版,现在它就像一个魅力.

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.

始终从maven存储库下载您的库.

Always download your libs from the maven repos.

这篇关于使用Java在所有字段上的MongoDB文本索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆