Reputation: 1373
I have written a select query in cosmos db which works fine. But in that query when i try to add order by column on a alias column it does not work. Here distance is an alias column What is the correct way to do it ?
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
Upvotes: 4
Views: 1704
Reputation: 23782
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”
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.
Upvotes: 5