问题描述
在使用Mongo API的Azure CosmosDB上,我创建一个具有固定名称的索引,并使用mongo-go-driver打印该名称:
m := mongo.IndexModel {
Keys: bson.D{{Key: "id",Value: 1},{Key: "parent",Value: 1}},Options: options.Index().SetUnique(true)SetName("testIndexName"),}
opts := options.CreateIndexes().SetMaxTime(time.Minute)
indexName,err := col.Indexes().CreateOne(ctx,m,opts)
fmt.Println(indexName)
create调用返回的索引名称是提供的名称:testIndexName
。但是,当我通过MongoDB API或直接使用mongo shell在Azure门户中列出集合上的索引时,它将为新创建的索引返回默认索引名称:
{
"v" : 1,"unique" : true,"key" : {
"id" : 1,"parent" : 1
},"name" : "id_1_parent_1","ns" : "testdbindexed.testcol"
}
当我在mongodb上本地运行代码时,我获得了新创建索引的提供的索引名称。
有人遇到过这个问题吗?对我来说似乎是个虫子。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)