获取Azure DocumentDb中的记录数 [英] Get record count in Azure DocumentDb

查看:83
本文介绍了获取Azure DocumentDb中的记录数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在azure网站上的documentdb允许并通过documentdb资源管理器( https不支持://studiodocumentdb.codeplex.com/).迄今为止,获取已找到的记录计数的唯一方法是从代码中获取(请参见下文).但是,现在崩溃了,我们的收藏集中有足够的文件.有没有一种方法可以计算出集合中有多少文档比我的解决方案有用?

It seems like 'select count(*) from c' in the SQL queries allowed by documentdb in the azure site and through the documentdb explorer (https://studiodocumentdb.codeplex.com/) is not supported. To date, the only way to get a record count that I have found is from code (see below). However, there are enough files in our collection now that this is crashing. Is there a way to get a count on how many documents in a collection that works more than my solution?

DocumentClient dc = GetDocumentDbClient();
var databaseCount = dc.CreateDatabaseQuery().ToList();
Database azureDb = dc.CreateDatabaseQuery().Where(d => d.Id == Constants.WEATHER_UPDATES_DB_NAME).ToArray().FirstOrDefault();

var collectionCount = dc.CreateDocumentCollectionQuery(azureDb.SelfLink).ToList();

DocumentCollection update = dc.CreateDocumentCollectionQuery(azureDb.SelfLink).Where(c => c.Id == "WeatherUpdates").ToArray().FirstOrDefault();

var documentCount = dc.CreateDocumentQuery(update.SelfLink, "SELECT * FROM c").ToList();

MessageBox.Show("Databases: " + databaseCount.Count().ToString() + Environment.NewLine
                +"Collections: " + collectionCount.Count().ToString() + Environment.NewLine
                + "Documents: " + documentCount.Count().ToString() + Environment.NewLine, 
                 "Totals", MessageBoxButtons.OKCancel); 

推荐答案

在执行"count"关键字之前,应在服务器上的存储过程中进行查询.如果只想计数,请注意不要获取查询中的所有列/属性.

Until the implementation of the "count" keyword, you should do your query in a store procedure on the server. Take care to not get all columns/properties in your query if you want only a count.

仅选择ID,例如;

  dc.CreateDocumentQuery(update.SelfLink, "SELECT c.id FROM c")

这篇关于获取Azure DocumentDb中的记录数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆