sample json data file
{
"Includes": {
"Employees": {
"14": {
"name": "john",
"age": 12,
"activity": {
"Count": 3502,
"RatingValue": 5
}
},
"17": {
"name": "smith",
"age": 23,
"activity": {
"Count": 232,
"RatingValue": 5
}
}
}
}
}
js was written to retrieve the nested document and stored in array
var result = [];
db.details.find().forEach(function(doc) {
var Employees = doc.Includes.Employees;
if (Employees) {
for (var key in Employees) {
var Employee = Employees[key];
var item = [];
item.push(key);
item.push(Employee.name);
item.push(Employee.age);
item.push(Employee.activity.Count);
item.push(Employee.activity.RatingValue);
result.push(item.join(","));
}
}
});
print(result);
How can we store the output of array in csv with 2 rows because the data contains 2 rows by using mongoexport. In csv output must be
14,john,12,3502,5
17,smith,23,232,5
var Employees = doc.Includes.Empoyees;. Empoyees -> Employees