documentDB 的文档表明它在这里提供自动索引: https://azure.microsoft.com/en-us/documentation/articles/documentdb-indexing/
但它的示例代码(在 Azure 门户上)显示了手动索引策略创建,如下所示:
DocumentCollection collectionInfo = new DocumentCollection();
collectionInfo.Id = collectionName;
// Configure collections for maximum query flexibility including string range queries.
collectionInfo.IndexingPolicy = new IndexingPolicy(new RangeIndex(DataType.String) {
Precision = -1
});
如果documentDB提供了自动索引,那为什么我还需要再次手动创建索引策略?
最佳答案
每个字段都有一个默认的 3 字节哈希索引。您可以使用索引策略设置覆盖特定字段/类型的索引策略。如果您想要范围索引或想要更改索引的精度,可以使用策略来实现。您需要在任何要使用 ORDER BY
以及其他常见用途的字段上设置范围索引。所以,是的,这两种说法都是正确的。它提供自动索引,但您也可以指定索引。
关于azure - DocumentDB 是否提供自动索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38549373/