JSON Structure Data Manipulation in MongoDB -


i new mongodb , facing problem data structure. hierarchy of data not visible. instance, have data in format of

{         "fcilty_id" : 154,         "acct_no" : 2.14782e+008,         "string_dc_cd" : 8,         "string_dts" : "25-jan-14",         "string_id_no" : 1,         "string_item_no" : 0,         "child_of_cd" : "",         "bintype_no" : 244,         "ptxt_code_str" : "8.1.71.4.0.0.0.13",         "ptxt_desc_txt" : "dc date =",         "value_no" : 2.37024e+007,         "value_freetext_txt" : "",         "value_dts" : "25-jan-14"  }  {      "fcilty_id" : 154,     "acct_no" : 2.14782e+008,     "string_dc_cd" : 8,     "string_dts" : "25-jan-14",     "string_id_no" : 1,     "string_item_no" : 2,     "child_of_cd" : "",     "bintype_no" : 244,     "ptxt_code_str" : "8.1.71.4.0.0.0.167",     "ptxt_desc_txt" : "start time",     "value_no" : 2.37024e+007,     "value_freetext_txt" : "",     "value_dts" : "25-jan-14" }  {     "fcilty_id" : 154,     "acct_no" : 2.14782e+008,     "string_dc_cd" : 8,     "string_dts" : "25-jan-14",     "string_id_no" : 1,     "string_item_no" : 3,     "child_of_cd" : "",     "bintype_no" : 241,     "ptxt_code_str" : "8.1.71.4.0.0.0.153",     "ptxt_desc_txt" : "order type",     "value_no" : 0,     "value_freetext_txt" : "",     "value_dts" : "" } 

i trying hard not able make data in ideal structure using aggregate , update. have data structure like

    {      "fcilty_id" : 154,         "acct_no" : 2.14782e+008,         "string_dc_cd" : 8,         "string_dts" : "25-jan-14",         "string_id_no" : 1,          "item": [ {      {"string_item_no" : 0,         "child_of_cd" : "",         "bintype_no" : 244,         "ptxt_code_str" : "8.1.71.4.0.0.0.13",         "ptxt_desc_txt" : "dc date =",         "value_no" : 2.37024e+007,         "value_freetext_txt" : "",         "value_dts" : "25-jan-14"}      {     "string_item_no" : 2,         "child_of_cd" : "",         "bintype_no" : 244,         "ptxt_code_str" : "8.1.71.4.0.0.0.167",         "ptxt_desc_txt" : "start time",         "value_no" : 2.37024e+007,         "value_freetext_txt" : "",         "value_dts" : "25-jan-14"}      {     "string_item_no" : 3,         "child_of_cd" : "",         "bintype_no" : 241,         "ptxt_code_str" : "8.1.71.4.0.0.0.153",         "ptxt_desc_txt" : "order type",         "value_no" : 0,         "value_freetext_txt" : "",         "value_dts" : ""}     }  ]    } 

is feasible in mongodb? if not there other tool can use achieve this. want insert data in apache drill before want data structure in proper hierarchy. in advance!

use mongo aggregation framework results.

1> first group fcilty_id,acct_no,string_dc_cd,string_dts,string_id_no

2> push remaining data item

3> last used project.

so mongo aggregation query looks :

db.collectionname.aggregate([     {         "$group": {             "_id": {                 "fcilty_id": "$fcilty_id",                 "acct_no": "$acct_no",                 "string_dc_cd": "$string_dc_cd",                 "string_dts": "$string_dts",                 "string_id_no": "$string_id_no"             },             "item": {                 "$push": {                     "string_item_no": "$string_item_no",                     "child_of_cd": "$child_of_cd",                     "bintype_no": "$bintype_no",                     "ptxt_code_str": "$ptxt_code_str",                     "ptxt_desc_txt": "$ptxt_desc_txt",                     "value_no": "$value_no",                     "value_freetext_txt": "$value_freetext_txt",                     "value_dts": "$value_dts"                 }             }         }     },     {         "$project": {             "_id": 0,             "fcilty_id": "$_id.fcilty_id",             "acct_no": "$_id.acct_no",             "string_dc_cd": "$_id.string_dc_cd",             "string_dts": "$_id.string_dts",             "string_id_no": "$_id.sid",             "item": 1         }     } ]).pretty() 

if want add above result in new collection add $out in aggregation.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -