[英]How to change mongodb index name
这是我使用的索引的名称
LongitudeLatitude_indexContents_1_prominent_-1
-1th的问题是有问题的,并自动生成。 我想将其更改为LongitudeLatitude_indexContents_1_prominent_min1
或者其他的东西
索引需要一段时间。 所以我宁愿只是更改索引的名称。
例如,
如果我做
db.tablebusiness.find({ "LongitudeLatitude" : { "$nearSphere" : [106.772835, -6.186753], "$maxDistance" : 0.044983732050783008 }, "Prominent" : { "$gte" : 15 }, "indexContents" : { "$all" : [/^warung/] } }).hint("LongitudeLatitude_indexContents_1_Prominent_-1").limit(50).explain();
我懂了
> ).hint("LongitudeLatitude_indexContents_1_Prominent_-1").limit(50).explain();
Thu Sep 06 11:01:51 uncaught exception: error: { "$err" : "bad hint", "code" : 1
0113 }
你为什么要使用hint()
? 那一定是我见过的最不可靠的证明代码。 如果您的查询没有有效地使用索引,那么您应该真正更改查询或添加另一个索引以使查询在索引上运行。 强制MongoDB使用无法找到的索引实际上可能会进一步降低查询速度,因为它将尝试使用不提供快捷方式的b树。
体现您的查询:
db.tablebusiness.find({ "LongitudeLatitude" : { "$nearSphere" : [106.772835, -6.186753], "$maxDistance" : 0.044983732050783008 }, "Prominent" : { "$gte" : 15 }, "indexContents" : { "$all" : [/^warung/] } })
将使用您创建的索引,而无需使用hint()
。 如果您对这一查询的索引更好地提高了一天的查询效率,则由于使用了新的索引,因此使用hint()
将使此查询不再更快。 不仅如此,您还必须在所有代码中更改索引名称。
至于更改索引的名称:我认为您必须先删除它,然后重新索引以创建自己名称的新索引(尽管如@Thilo所述,自命名索引将被删除)。
.hint(“ LongitudeLatitude_indexContents_1_Prominent_-1”)
应该
.hint({LongitudeLatitude_indexContents:1,Prominent:-1})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.