2016-01-15 24 views
1

我收到錯誤消息Uncaught Error: When the modifier option is true, validation object must have at least one operator錯誤:試圖更新

我看similarquestions一個number時「未捕獲錯誤當改性劑的選擇是正確,驗證對象必須至少有一個運營商」,但一直沒能破譯這有什麼錯我的查詢:

Meteor.users.update({ 
    _id: Meteor.user()._id 
}, { 
    $set: { 
     "emails.letter": true 
    } 
}) 

我的MongoDB的結構如下:

{ 
    "_id": "ujkwQp4rYTKQeLq3F", 
    "emails": [{ 
     "address": "[email protected]", 
     "letter": false 
    }] 
} 
+0

我認爲你將'emails'定義爲一個數組,但是像'letter'這樣的行爲是屬性。嘗試取出括號,這樣'emails'是一個對象。這有幫助嗎? – terrafirma9

+0

可能會有多封電子郵件,所有這些郵件都會有自己的驗證,所以我無法更改模型@ terrafirma9 – maudulus

回答

1

您需要指定要更新的數組中的哪個元素。試試這個:

Meteor.users.update({ 
    _id : 123456, 
    "emails.address":"[email protected]" 
}, { 
    $set: { 
     "emails.$.letter": true 
    } 
});