Retrieve The Values From Array And Store It In Csv File Using Mongodb
This is input json file. Javascript code is written to iterate using MongoDB. { 'Includes': { 'Employees': { '14': { 'name': 'john', 'age': 12,
Solution 1:
Change that final print(result);
to the following:
print("Id,name,age,count,RatingValue");
print(result.join("\n"));
Note: The first line is just for the column headers; the second line prints each employee result on a separate line.
Then call your script and direct the output to a CSV file like so:
mongo --quiet "full-path-to-script.js" > "full-path-to-output.csv"
Note: The --quiet
arg suppresses the standard Mongo header output (shell version and initial database).
I created a details collection, and added your JSON document to it, and then running the modified script resulted in the following CSV file content:
Id,name,age,count,RatingValue
14,john,12,3502,5
17,smith,23,232,5
Post a Comment for "Retrieve The Values From Array And Store It In Csv File Using Mongodb"