1
MongoDB更新方法有點問題。這是我的(簡化)模式:更新MongoDB上的子元素
{
profile: {
birthdate: "XXX",
city: "xxx"
},
account: {
username: "...",
password: "....",
visits: 0
}
}
我已經在數據庫中有2000個對象。我想通過刪除用戶名值匿名化數據。
我嘗試這樣做:
db.users.update({}, {$set: account: {username: ""}}, false, true);
這不作品,這個查詢中刪除密碼字段和訪問。我明白爲什麼,但怎麼辦?
db.users.update({}, {account: { $set: {username: ""}}}, false, true);
mongo想分配「$ set」字段,以至於不能工作。
我的問題是:如何更新後代字段而不刪除整個「帳戶」子文檔?
(設置 「UPSERT」 真不相同。)
謝謝,但那不起作用 > db.users.update({},{$ set:{account.username:「」}},false,true) Fri Mar 1 11:52:21編譯錯誤:(shell):1 SyntaxError:意外的標記。 我應該保留用戶名,因爲這個數據庫將與其他需要知道該字段存在的人共享。但我必須隱藏現有的用戶名(我會把一些隨機數據) – Metal3d 2013-03-01 10:54:25
我的上帝......好吧......我忘記用雙引號!非常感謝 ! – Metal3d 2013-03-01 10:55:21