Kavya Durgam

Kavya Durgam

  • 1.9k
  • 26
  • 21.8k

How to export nested array data from mongodb to csv

Feb 12 2018 6:45 AM
I have the below json format of document in my collection in mongodb.Now i need to export this data into csv with only specified fields and i dont want frequency_serving "Never" value object(Under VFoodDetails Array)in csv.What i tried the below command
 
  1. -c FrequencyQuestionForm --type=csv --fields data.formList.IdentificationDetails.Group_Id,data.formList.IdentificationDetails.Study_Name -q '{"data.formList.IdentificationDetails.Study_Id":"1"}' --out D:/MongoDBReports/Book1.csv 
 it throws an error like this
 
"too many positional arguments: [dbmongo 27017 FormDataBase FrequencyQuestionForm 'data.formList.0.IdentificationDetails.0.Group_ Id,data.formList.0.IdentificationDetails.0.Study_Name'] 2018-02-12T17:37:58.012+0530 try 'mongoexport --help' for more information"
 
  1. [  
  2.       {  
  3.         "_id""5a6026e29cbcdc48083dae1a",  
  4.         "data": {  
  5.           "formList": [  
  6.             {  
  7.               "IdentificationDetails": [  
  8.                 {  
  9.                   "Status""Data Entry Completed",  
  10.                   "Form_Id": 1,  
  11.                   "Interviewer_Name""NAGARAJ.P",  
  12.                   "Group_Id": 9,  
  13.                   "Study_Id""1",  
  14.                   "Study_Name""INDIAB",  
  15.                   "Created_Emp_Id""1",  
  16.                   "Form_Name""Food Frequency Questionnarie",  
  17.                   "Visit_No""1",  
  18.                   "Volunteer_Id""R270116",  
  19.                   "Interview_Date""2009-10-10T00:00:00Z",  
  20.                   "Volunteer_Name""RAJENDRA PAWAR"  
  21.                 }  
  22.               ]  
  23.             },  
  24.             {  
  25.               "VFoodDetails": [  
  26.                 {  
  27.                   "Portion_Size": 15,  
  28.                   "Serving_Size""0",  
  29.                   "Food_Id": 737,  
  30.                   "Value""0",  
  31.                   "Portion_Tool": 18,  
  32.                   "Volunteer_Id""R270116",  
  33.                   "Meal_Session": 121,  
  34.                   "Frequency_Serving""Daily"  
  35.                 },  
  36.                 {  
  37.                   "Portion_Size": 168,  
  38.                   "Serving_Size""0",  
  39.                   "Food_Id": 740,  
  40.                   "Value""0",  
  41.                   "Portion_Tool": 177,  
  42.                   "Volunteer_Id""R270116",  
  43.                   "Meal_Session": 121,  
  44.                   "Frequency_Serving""Never"  
  45.                 }  
  46.               ]  
  47.             }  
  48.           ]  
  49.         }  
  50.       },  
  51.       {  
  52.         "_id""5a6026e29cbcdc46783dae1a",  
  53.         "data": {  
  54.           "formList": [  
  55.             {  
  56.               "IdentificationDetails": [  
  57.                 {  
  58.                   "Status""Data Entry Completed",  
  59.                   "Form_Id": 1,  
  60.                   "Interviewer_Name""NAGARAJ.P",  
  61.                   "Group_Id": 9,  
  62.                   "Study_Id""1",  
  63.                   "Study_Name""INDIAB",  
  64.                   "Created_Emp_Id""1",  
  65.                   "Form_Name""Food Frequency Questionnarie",  
  66.                   "Visit_No""1",  
  67.                   "Volunteer_Id""R270176",  
  68.                   "Interview_Date""2009-10-10T00:00:00Z",  
  69.                   "Volunteer_Name""KUMARAN PAWAR"  
  70.                 }  
  71.               ]  
  72.             },  
  73.             {  
  74.               "VFoodDetails": [  
  75.                 {  
  76.                   "Portion_Size": 15,  
  77.                   "Serving_Size""0",  
  78.                   "Food_Id": 737,  
  79.                   "Value""0",  
  80.                   "Portion_Tool": 18,  
  81.                   "Volunteer_Id""R270176",  
  82.                   "Meal_Session": 121,  
  83.                   "Frequency_Serving""Never"  
  84.                 },  
  85.                 {  
  86.                   "Portion_Size": 168,  
  87.                   "Serving_Size""0",  
  88.                   "Food_Id": 740,  
  89.                   "Value""0",  
  90.                   "Portion_Tool": 177,  
  91.                   "Volunteer_Id""R270176",  
  92.                   "Meal_Session": 121,  
  93.                   "Frequency_Serving""Weekly"  
  94.                 }  
  95.               ]  
  96.             }  
  97.           ]  
  98.         }  
  99.       }  
  100.     ] 
 
 
 

Brought to you by:

Answers (1)