CosmosDB - 创建索引
CosmosDB - Create Index
我在 CosmosDB 中创建了一个新集合,我正在尝试创建我的第一个索引。
我运行以下脚本:
db.getCollection("mycoll").createIndex({ "UniqueId": 1 }, { "name": "udx_mycoll_UniqueId", "unique": true });
它产生响应:
{
"_t" : "CreateIndexesResponse",
"ok" : 1,
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 3,
"numIndexesAfter" : 4
}
这看起来很有希望,但是当我 运行 查询时:
db.mycoll.getIndexes();
没有找到索引。我也在 Compass 中尝试了 运行ning 它,当我切换到索引选项卡时出现错误:
'$indexState' is not supported
任何人都可以阐明这一点吗?
如果你使用 Robo3T client 就可以了。
但是,不考虑自定义名称。
你的情况:
db.getCollection("mycoll").createIndex({ "UniqueId": 1 }, { "name": "udx_mycoll_UniqueId", "unique": true });
你最终会得到一个名为:UniqueId_1
的索引
我在 CosmosDB 中创建了一个新集合,我正在尝试创建我的第一个索引。
我运行以下脚本:
db.getCollection("mycoll").createIndex({ "UniqueId": 1 }, { "name": "udx_mycoll_UniqueId", "unique": true });
它产生响应:
{
"_t" : "CreateIndexesResponse",
"ok" : 1,
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 3,
"numIndexesAfter" : 4
}
这看起来很有希望,但是当我 运行 查询时:
db.mycoll.getIndexes();
没有找到索引。我也在 Compass 中尝试了 运行ning 它,当我切换到索引选项卡时出现错误:
'$indexState' is not supported
任何人都可以阐明这一点吗?
如果你使用 Robo3T client 就可以了。
但是,不考虑自定义名称。
你的情况:
db.getCollection("mycoll").createIndex({ "UniqueId": 1 }, { "name": "udx_mycoll_UniqueId", "unique": true });
你最终会得到一个名为:UniqueId_1
的索引