2

I'm using cosmosdb with azure table api and no where can I see any way to get total records count from a table. Can see that there are ways to get count of records with sql api. What is the best possible way to get count using azure table apis? I'm using nodejs to connect to this instance.

2 Answers2

0

What is the best possible way to get count using azure table apis?

Based on my researching and rest api, unfortunately, there is no directly way to get count using azure table api which is similar to count keyword in sql api query.

One way to do so would be to list all entities in a table and get their count. This is an utterly horrid approach and can be a bit costly if you have to iterate through billions of records. Best you can do is do a projected query to enumerate through all the Partition & Row keys and sum them up thus controlling the cost and time of the operation.

In addition,you could send your desired requirement in cosmos db feedback.

Jay Gong
  • 23,163
  • 2
  • 27
  • 32
0

I found this page: https://microsoft.github.io/AzureTipsAndTricks/blog/tip152.html

I tried to do the same in nodejs and it worked for me:

await container.items.query('SELECT VALUE COUNT(1) FROM c', {maxItemCount: -1}).fetchAll();
Coyote
  • 159
  • 2
  • 11