Hello I need to count collections in my database with c#
if I use run command i wrote db.stats()'. but I don`t know how use this command in c#
Good thing that the mongo shell is a REPL. So evaluate the internals of the function there like this:
> db.stats
function (scale){
return this.runCommand( { dbstats : 1 , scale : scale } );
}
So all you need now is the command invocation for c#
var commandDoc = {
{ "dbstats", 1 }
};
var commandResult = db.RunCommand( commandDoc );
If all you need is the count of the collections in a specific database, most likely using following should work fine:
MongoDatabase mdb = XXX;
IEnumerable<string> collNames = _mdb.GetCollectionNames();
collNames will have all collection names in the database and the count of that is the number of collections under that database. Most likely you may want to filter that collection for system collections like system.users, system.profile etc.
db? Please try harder to ask a question I can answer without reading your mind.