C# 我可以按任何属性对DocumentDB中的数据进行排序吗?
我想从documentDB查询中获取有序数据,当然,我知道documentDB不支持orderBY或排序概念,但是可以编写存储过程来获取排序列表 我的问题类似于C# 我可以按任何属性对DocumentDB中的数据进行排序吗?,c#,sorting,stored-procedures,azure-cosmosdb,C#,Sorting,Stored Procedures,Azure Cosmosdb,我想从documentDB查询中获取有序数据,当然,我知道documentDB不支持orderBY或排序概念,但是可以编写存储过程来获取排序列表 我的问题类似于 SELECT root.id FROM Root root WHERE (root.age< 30) {"Exception: Microsoft.Azure.Documents.BadRequestException, message: {\"Errors\":[\"Encountered exception while ex
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"}
从这个异常中,我了解到集合应该由某些属性索引,而我的集合没有索引
为此,我可以为我的集合应用索引,但如果我想按name的其他属性对排序列表进行排序,则可能无法使用索引
有人能帮忙解决这个问题吗
我的直截了当的问题是“是否可以使用存储过程根据任何属性从documentdb获取排序列表(升序/降序)
下面的解决方案对于按属性获取排序列表效果良好,但当我想按子属性(例如:s.Name.FirstName,其中Name是一个包含三个属性FirstName、MiddleName和LastName)获取排序列表顺序时,该解决方案不起作用
有人能帮我做这个吗
提前感谢是的,这可以通过在整个集合上指定范围索引来实现,如下所示。有关更多详细信息,请参阅此处的文档:
我的收藏有大约3-40万个文档,我使用了所有三个收藏,在不丢失数据的情况下,我如何实现上述内容?按任何字段排序是否有效?(单据子单据属性)@Aravindy您的解决方案适用于orderby属性,但不适用于子属性:(
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);