简体   繁体   English

nodejs cosmosdb 获取表中的总记录数

[英]nodejs cosmosdb get count of total records in a table

I'm using cosmosdb with azure table api and no where can I see any way to get total records count from a table.我正在将 cosmosdb 与 azure table api 一起使用,但我在哪里看不到任何从表中获取总记录数的方法。 Can see that there are ways to get count of records with sql api.可以看到有一些方法可以使用 sql api 获取记录数。 What is the best possible way to get count using azure table apis?使用 azure table api 获取计数的最佳方法是什么? I'm using nodejs to connect to this instance.我正在使用 nodejs 连接到这个实例。

What is the best possible way to get count using azure table apis?使用 azure table api 获取计数的最佳方法是什么?

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.根据我的研究休息 api ,不幸的是,没有直接的方法使用 azure table api 来获取计数,这类似于 sql api 查询中的count关键字。

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 .此外,您可以在cosmos db 反馈中发送您想要的要求。

I found this page:https://microsoft.github.io/AzureTipsAndTricks/blog/tip152.html我找到了这个页面:https ://microsoft.github.io/AzureTipsAndTricks/blog/tip152.html

I tried to do the same in nodejs and it worked for me:我尝试在 nodejs 中做同样的事情,它对我有用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM