我可以按任何属性对 DocumentDB 中的数据进行排序吗?
Can I sort the data in DocumentDB by any attribute?
我想从 documentDB 查询中获取有序数据,当然,我知道 DocumentDB 不支持 orderBY 或排序概念,但是可以编写存储过程来获取排序列表,
我的查询类似于
SELECT root.id FROM Root root WHERE (root.age< 30)
我想要按年龄排序的列表顺序。
当我尝试 运行 存储过程时,它引发了聚合异常,类似于
{"Exception: Microsoft.Azure.Documents.BadRequestException, message: {\"Errors\":[\"Encountered exception while executing function. Exception = Error: {\\"Errors\\":[\\"An invalid query has been specified with filters against path(s) that are not range-indexed. Consider adding allow scan header in the request.\\"]}\r\nStack trace: Error: {\\"Errors\\":[\\"An invalid query has been specified with filters against path(s) that are not range-indexed. Consider adding allow scan header in the request.\\"]}\n at callback (OrderBy.js:54:13)\n at Anonymous function (OrderBy.js:521:29)\"]}, request URI: rntbd://10.98.107.60:14900/apps/4c8d65d7-216b-46b4-abb7-52c1a0c7123f/services/appcrest-ServerService-1/partitions/cf963206-7d13-4b94-9f03-06954e03f667/replicas/130737244172846540p\r\nActivityId: 7aeab81e-db33-4a7d-9bb6-172966d9cc60"}
从这个异常中,我了解到 collection 应该被一些 属性 索引,而我的 collection 没有被索引,
为此,我可以为我的 collection 应用索引,但如果我想获得由其他 属性 名称
排序的列表,它可能无法工作
有人可以帮助解决这个问题吗?
我的直接问题是 "is it possible to get sorted list(ascending/descending) from documentdb based on any property using stored procedures?"
下面的解决方案可以很好地通过 属性 获取排序列表,但是当我想通过子 属性 获取排序列表顺序时(例如:s.Name.FirstName 其中名称是 属性,其中包含三个属性 FirstName、MiddleName 和 LastName)不起作用。
有人可以帮我做这个吗?
提前致谢
是的,这可以通过在整个集合上指定范围索引来实现,如下所示。有关详细信息,请参阅此处的文档:http://azure.microsoft.com/documentation/articles/documentdb-indexing-policies/
var rangeDefault = new DocumentCollection { Id = "rangeCollection" };
rangeDefault.IndexingPolicy.IncludedPaths.Add(
new IndexingPath {
IndexType = IndexType.Range,
Path = "/",
NumericPrecision = 7 });
rangeDefault = await client.CreateDocumentCollectionAsync(
database.SelfLink,
rangeDefault);
我想从 documentDB 查询中获取有序数据,当然,我知道 DocumentDB 不支持 orderBY 或排序概念,但是可以编写存储过程来获取排序列表,
我的查询类似于
SELECT root.id FROM Root root WHERE (root.age< 30)
我想要按年龄排序的列表顺序。
当我尝试 运行 存储过程时,它引发了聚合异常,类似于
{"Exception: Microsoft.Azure.Documents.BadRequestException, message: {\"Errors\":[\"Encountered exception while executing function. Exception = Error: {\\"Errors\\":[\\"An invalid query has been specified with filters against path(s) that are not range-indexed. Consider adding allow scan header in the request.\\"]}\r\nStack trace: Error: {\\"Errors\\":[\\"An invalid query has been specified with filters against path(s) that are not range-indexed. Consider adding allow scan header in the request.\\"]}\n at callback (OrderBy.js:54:13)\n at Anonymous function (OrderBy.js:521:29)\"]}, request URI: rntbd://10.98.107.60:14900/apps/4c8d65d7-216b-46b4-abb7-52c1a0c7123f/services/appcrest-ServerService-1/partitions/cf963206-7d13-4b94-9f03-06954e03f667/replicas/130737244172846540p\r\nActivityId: 7aeab81e-db33-4a7d-9bb6-172966d9cc60"}
从这个异常中,我了解到 collection 应该被一些 属性 索引,而我的 collection 没有被索引,
为此,我可以为我的 collection 应用索引,但如果我想获得由其他 属性 名称
排序的列表,它可能无法工作有人可以帮助解决这个问题吗?
我的直接问题是 "is it possible to get sorted list(ascending/descending) from documentdb based on any property using stored procedures?"
下面的解决方案可以很好地通过 属性 获取排序列表,但是当我想通过子 属性 获取排序列表顺序时(例如:s.Name.FirstName 其中名称是 属性,其中包含三个属性 FirstName、MiddleName 和 LastName)不起作用。
有人可以帮我做这个吗?
提前致谢
是的,这可以通过在整个集合上指定范围索引来实现,如下所示。有关详细信息,请参阅此处的文档:http://azure.microsoft.com/documentation/articles/documentdb-indexing-policies/
var rangeDefault = new DocumentCollection { Id = "rangeCollection" };
rangeDefault.IndexingPolicy.IncludedPaths.Add(
new IndexingPath {
IndexType = IndexType.Range,
Path = "/",
NumericPrecision = 7 });
rangeDefault = await client.CreateDocumentCollectionAsync(
database.SelfLink,
rangeDefault);