2015-05-27 41 views
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 
        } 
        } 
       } 
      } 
     } 
     } 
    } 
} 

必須從每個子文檔中刪除count_data?如何刪除或取消設置多個嵌套級別的MongoSubdocument或字段?

如何通過多級嵌套元素刪除或取消設置MongoSubdocument?

+2

PLZ格式,或讓別人去做。以便它變得可讀。 –

+0

Stackoverflow內容空間不允許我這樣做。請把jsondata和在這裏檢查http://codebeautify.org/jsonviewer Thankyou提前 –

回答

1

您的收藏太複雜,無法處理。 我不建議在文檔中有這樣的文檔結構和$ unset每個字段。不過,如果你想取消設置count_data在蒙戈使用$unset -

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": "" 
    } 
}) 
相關問題