首页 > 解决方案 > Azure cosmos db 别名列 order by

问题描述

我在 cosmos db 中编写了一个运行良好的选择查询。但是在那个查询中,当我尝试在别名列上按列添加顺序时,它不起作用。这里的距离是一个别名列 正确的方法是什么?

SELECT c.id,c.type,c.name,c.latitude,c.longitude,c.location, ST_Distance(c.location, { 'type': 'Point', 'coordinates':[-112.215641, 33.181647]}) as distance FROM c WHERE ST_Distance(c.location, { 'type': 'Point', 'coordinates':[-112.215641, 33.181647]}) < 321868.8 ORDER BY c.distance ASC

标签: azureazure-cosmosdb

解决方案


Actually,we are told that we can only sort with properties of document, not derived values. Please see this link.You distance column is derived value,can't be used at order by.

“Unsupported ORDER BY clause. ORDER BY item expression could not be mapped to a document path”</p>

I would suggest you sort the query result by yourself.For example,in .net code,you could use Sort function to sort the result by the column.


推荐阅读