0

Hi I have used aggregation in Mongo similar to the one shown in the below link MongoDB Return the count of documents for each day for the last one month

I am getting the output as

/* 0 */    
{
    "result" : [ 
        {
            "_id" : "2014-03-17",   
            "count" : 1
        },   
        {
            "_id" : "2014-03-15",  
            "count" : 9
        }        
    ],  
    "ok" : 1  
} 

I need the result to be displayed in a table format so that I want to save this two columns in an excel sheet for future reference..

Community
  • 1
  • 1
user3376856
  • 43
  • 1
  • 5

2 Answers2

0

Mongodb is a document oriented data base, so you need to write a small code to do the job for you. Or google to get the code one guy already write like the one on the question How to convert JSON to CSV format and store in a variable and adapt it to your case.

Community
  • 1
  • 1
innoSPG
  • 4,268
  • 1
  • 24
  • 40
0

The result of the aggregate command is an array, and cannot currently be returned otherwise. In JavaScript, you iterate an array to do what you want with the underlying result in a manner similar to this:

var data = db.collection.aggregate([ /* your aggregation */ ]);

data.result.forEach(function(doc) {

    // do something with `doc`

});

Other languages will have similar handling or possibly even another type to handle the aggregate result.

In future releases, the results of aggregate will be a cursor which you iterate just like a standard cursor from find.

Neil Lunn
  • 130,590
  • 33
  • 275
  • 280