2011-10-13 58 views
11

在shell下,我的查詢是:更新查詢殼

db.checkin_4e95ae0926abe9ad28000001.update({location_city:"New York"}, {location_country: "FUDGE!"}); 

但是,它實際上並沒有更新我的記錄。它也沒有錯誤。當我運行此之後做了db.checkin_4e95ae0926abe9ad28000001.find({location_city:"New York"});,我讓所有我的結果,但location_country並沒有改變:

{ 
    "_id": ObjectId("4e970209a0290b70660009e9"), 
    "addedOn": ISODate("2011-10-13T15:21:45.772Z"), 
    "location_address1": "", 
    "location_city": "New York", 
    "location_country": "United States", 
    "location_latLong": { 
     "xLon": -74.007124, 
     "yLat": 40.71455 
    }, 
    "location_source": "socialprofile", 
    "location_state": "New York", 
    "location_zip": "" 
} 

回答

22

這是因爲在update函數的第二個參數,你需要使用$set運營商更新location_country如下面的例子中:

db.checkin_4e95ae0926abe9ad28000001.update(
    {location_city:"New York"}, //find criteria 
    // this row contains fix with $set oper 
    { $set : { location_country: "FUDGE!"}}); 

Here你可以找到可用更新操作符的列表。