Change default record sorting for CosmosDB Gremlin API

Joe Cisar 1 Reputation point
2022-10-21T13:18:52.197+00:00

When I create a new Vertex in CosmosDB Gremlin API I believe there is a hidden _ts property that gets added to the record. This appears to be the default return order of vertices when performing a query, such as g.V().has('orgKey', ABC), my results come back in ascending order (oldest first).

Is there a way to change the default return order in CosmosDB GremlinAPI so that I get my results back newest first by default?

I am trying to avoid a full set scan when finding the newest record matching a clause and it seems I can do that easily if I can reverse the default order in which records are returned.

Query I currently have to write:

g.V().has('partitionKey', 1111).has('name', 'test-data').order().by('createdOn', decr).range(0, 10)

Query I want to be able to write

g.V().has('partitionKey', 1111).has('name', 'test-data').range(0, 10)

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,543 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. GeethaThatipatri-MSFT 29,017 Reputation points Microsoft Employee
    2022-10-22T13:40:46.187+00:00

    Hi, @Joe Cisar Welcome to the Microsoft Q&A forum, Thanks for posting your question.
    If I understand correctly you want to know if there is a way to change the default return order in CosmosDB GremlinAPI
    There is not, and the return order is technically based on rid not ts, The default return order is rid, However, order by with range does not imply a scan It will only fetch the range from the backend
    That does not stand in a more complex case where the ordering is not directly on the element.
    If you think it is doing a full scan, connecting the execution profile may give you more insight

    Regards
    Geetha

    1 person found this answer helpful.