2013-08-07 161 views
0

我想從文檔中刪除路徑對象。 我試圖使用$ unset運營商,但它要求價值,我不必給。 有沒有辦法從文檔中刪除整個子文檔?從文檔中刪除子文檔

{ 
    "Address" : { 
     "Country" : "temp", 
     "City" : "temp", 
     "Street" : "temp", 
     "House" : "temp", 
     "Apartment" : "temp" 
    }, 
    "Birthday" : { 
     "Date" : { 
      "Day" : "temp", 
      "Moth" : "temp", 
      "Year" : "temp" 
     } 
    }, 
    "ConnectionStatus" : "Offline", 
    "DisplayName" : "temp", 
    "Email" : "temp", 
    "FirstName" : "temp", 
    "LastName" : "temp", 
    "Password" : "temp", 
    "Path" : { 
     "Start" : { 
      "Longtitude" : 400, 
      "Latitude" : 300 
     }, 
     "End" : { 
      "Longtitude" : 500, 
      "Latitude" : 400 
     }, 
     "Milestones" : [ 
      { 
       "Longtitude" : 420, 
       "Latitude" : 320 
      }, 
      { 
       "Longtitude" : 450, 
       "Latitude" : 350 
      }, 
      { 
       "Longtitude" : 480, 
       "Latitude" : 380 
      } 
     ] 
    }, 
    "ProgressStatus" : "Safe", 
    "_id" : ObjectId("5201cadc5b4da1f65a000001") 
}} 

回答

1

db.coll.update({"_id" : ObjectId("5201cadc5b4da1f65a000001")}, {$unset: {Path : 1}})

你得給$未設置運營商的

的值與您的集合名稱替換coll

+1

它工作得很好! 1的含義是什麼? –

+1

@ShaolinRabbi從文檔: 「$ unset語句中字段的值(即上面的」「)不影響操作。」 這只是一種佔位符 –