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);
This is now possible in the year 2017 of our lord.
SELECT VALUE COUNT(1) FROM c
[ 1234 ]
Actually works at this point:
SELECT COUNT(c.id) FROM c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With