Hi All,

I am trying to show the mongodb collection size from redash query. I am tried the below on the mongo shell but the same executed in the Redash giving me error as invalid JSON format. Am I doing something wrong? Thanks for your response.

{
“collection”: “Application”,
“aggregate”: [
{
“$collStats”: {
“storageStats”: { },
}
},
{
“$project”: {
“collectionSize”:"$storageStats.size",
“averageDocumentSize”: “$storageStats.avgObjSize”
}
}
]
}

I’m suspecting its the extra comma at the end of this line:
“storageStats”: { },

Make sure when pasting JSON in your posts to wrap it in three backticks. It makes it easier to analyze.

@delphikit is correct. The comma following "storageStats" is not valid JSON.

{
  "collection": "Application",
  "aggregate": [
    {
      "$collStats": {
        "storageStats": { }
      }
    },
    {
      "$project": {
        "collectionSize": "$storageStats.size",
        "averageDocumentSize": "$storageStats.avgObjSize"
      }
    }
  ]
}

I apologize for replying late. You are all right, the comma created the trouble. Thanks for your replies