0
{  
   "_id":"zxxxxxx",
   "UserId":"xxxxxx",
   "MobileNum":"xxxxxxx",
   "Global":{  
      "count":2,
      "EventType":{  
         "MT":{  
            "count":2,
            "count_data":{  
               "20120302":2
            },
            "Language":{  
               "Tamil":{  
                  "count":2,
                  "count_data":{  
                     "20120302":2
                  },
                  "Genre":{  
                     "Comedy":{  
                        "count":2,
                       "count_data":{  
                           "20120302":2
                        }
                     },
                     "Romance":{  
                        "count":2,
                        "count_data":{  
                           "20120302":2
                        }
                     }
                  },
                  "Cast":{  
                     "Actor":{  
                        "Siddharth Narayan":{  
                           "count":2,
                           "count_data":{  
                              "20120302":2
                           }
                        },
                        "Amala Paul":{  
                           "count":2,
                           "count_data":{  
                              "20120302":2
                           }
                        }
                     },
                     "Director":{  
                        "Balaji Mohan":{  
                           "count":2,
                           "count_data":{  
                              "20120302":2
                           }
                        }
                     },
                     "Music":{  
                        "Thaman S":{  
                           "count":2,
                           "count_data":{  
                              "20120302":2
                           }
                        }
                     }
                   },
                  "Censor":{  
                     "U":{  
                        "count":2,
                        "count_data":{  
                           "20120302":2
                        }
                     }
                  }
               }
            },
            "Dayofweek":{  
               "Weekends":{  
                  "count":2,
                  "1145":{  
                     "count":2,
                     "count_data":{  
                        "20120302":2
                     }
                  }
               }
            }
         }
      }
   }
}

Have to remove count_data from every subdocument?

How do I remove or unset MongoSubdocument over multilevel nested element?

Dev
  • 13,492
  • 19
  • 81
  • 174
Vinay Sawant
  • 368
  • 2
  • 7
  • 23
  • 2
    plz format it or let others do it. so that it becomes readable. – Dev May 27 '15 at 10:23
  • Stackoverflow content space aint allowing me to do so.Please put the jsondata and check here http://codebeautify.org/jsonviewer Thankyou in advance – Vinay Sawant May 27 '15 at 10:37

1 Answers1

1

Your collection is too complex to handle. I do not recommend to have such a document structure and $unset each and every field in document. Still if you want to unset count_data use $unset in mongo -

db.collection.update(
{
    "_id": "zxxxxxx"
},
{
    $unset:
    {
    "Global.EventType.MT.count_data": "",
    "Global.EventType.MT.Language.Tamil.count_data": "",
    "Global.EventType.MT.Language.Tamil.Genre.Comedy.count_data": "",
    "Global.EventType.MT.Language.Tamil.Genre.Romance.count_data": "",
    "Global.EventType.MT.Language.Tamil.Cast.Actor.Siddharth Narayan": "",
    "Global.EventType.MT.Language.Tamil.Cast.Actor.Amala Paul.count_data": "",
    "Global.EventType.MT.Language.Tamil.Cast.Director.Balaji Mohan.count_data": "",
    "Global.EventType.MT.Language.Tamil.Cast.Music.Thaman S.count_data": "",
    "Global.EventType.MT.Language.Tamil.Censor.U.count_data": "",
    "Global.EventType.MT.Dayofweek.Weekends.1145.count_data": ""
    }
})
Vishwas
  • 6,967
  • 5
  • 42
  • 69