My overall goal is to run a query that shows all the collections with the amount of data / counts and so on.
I found the following command/query and try to run it like this:
MongoClient client = new MongoClient(server);
var db = client.GetDatabase(database);
const string mongoQueryA = "var collectionNames = db.getCollectionNames(), stats = []; " +
"collectionNames.forEach(function(n) { stats.push(db[n].stats()); }); " +
"stats = stats.sort(function(a, b) { return b['size'] - a['size']; }); ";
var command = new JsonCommand<BsonDocument>(mongoQueryA);
var test = db.RunCommand<BsonDocument>(command);
And the code fails here. Exceptions:
JSON reader was expecting a value but found 'var'.
My understanding is that this shoul be run as command?
Running the query in Robot T works as expected. Bonus the plan was to return the data in the following format ( Based on Json from running query manualy in Robot T)
class MongoCollectionInfo
{
public string ns { get; set; }
public long size { get; set; }
public long count { get; set; }
public long avgObjSize { get; set; }
public long storageSize { get; set; }
public long nindexes { get; set; }
public long totalIndexSize { get; set; }
}
var collectionNames...is not JSON.