Skip to content

Instantly share code, notes, and snippets.

@zleao
Created July 14, 2020 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zleao/35e14ef5d0c30e30729175a3f4a3293d to your computer and use it in GitHub Desktop.
Save zleao/35e14ef5d0c30e30729175a3f4a3293d to your computer and use it in GitHub Desktop.
Portable MongoDB snippet to get a count of the existing collections in a database
var database = client.CreateDatabaseQuery().Where(db => db.Id == Configuration.DatabaseName).ToList().FirstOrDefault();
var feedResult = await client.ReadDocumentCollectionFeedAsync(UriFactory.CreateDatabaseUri(database.Id));
var collectionCount = feedResult.Count;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment