Reputation: 13
I am wondering if there is any way to query using the AltLink and not the SelfLink?
SELECT * FROM c
--WHERE c._alt = 'dbs/DefaultDb/colls/DefaultColl/docs/cd9d67d5-b82e-4ec5-aad3-91e784906f6e'
WHERE c._self = 'dbs/Rr4MAA==/colls/Rr4MAOW90GI=/docs/Rr4MAOW90GIBAAAAAAAAAA==/'
UPDATE:
The reason im searching for a way to use the AltLink in SQL is due to the issue of a simple query for a document by its id will continusouly grow in cost as the collection grows. Where as the .net SDK allows the use of the AltLink to get the document and the cost is almost always between 1 to 1.5 RU.
Upvotes: 0
Views: 151
Reputation: 7200
There are a few things that I need to make clear for you before you can understand why what you are asking for doesn't make sense.
Direct reads using self/alt link and partition key value will ALWAYS be more efficient than queries with self/alt link and partition key value. It's just the way Cosmos works.
The reason why what you're asking for isn't even possible in the first place is because the id
value is not unique within a collection. You can have unlimited items with the same id
as long as they are in a different logical partition (which means that you id
value is only unique within it's own logical partition).
This means that in such a scenario, your AltLink
for every single document in a collection will be exactly the same. How would the server know which document you truly want? This is also true about the SelfLink
which is unique per document because it uses resource ids. However the server doesn't have the capability to know where this resource id lives unless you point it to a logical partition.
The way you should do what you are asking for is to use the Read
methods of the SDKs or the Read
method of the REST API, alongside the partition key value that you're looking for.
Upvotes: 1