在 azure 站点中的 documentdb 和通过 documentdb 资源管理器( https://studiodocumentdb.codeplex.com/)允许的 SQL 查询中,似乎不支持“select count(*) from c” 。迄今为止,获得我发现的记录计数的唯一方法是通过代码(见下文)。但是,现在我们的集合中有足够的文件,这正在崩溃。有没有办法计算一个集合中有多少文档比我的解决方案更有效?
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);