0
我想更新消息具有特定ID並且用戶標識位於收件人數組中的子文檔的值。我想用指定的用戶ID更新匹配對象的值。FeathersJS Mongoose:更新匹配的子文檔無法正常工作
當我上運行的MongoDB CLI下面的查詢,一切正常和值更新:
db.getCollection('messages').update({
_id : ObjectId("57d7edb8c497a75a6a7fde60"),
"recipients.userId" : "5789127ae2bcc79326462dbc"
},{
$set : {"recipients.$.read": true}
});
但是當我運行通過JS以下查詢在我FeathersJS應用:
messageService.update({
_id : '57d7edb8c497a75a6a7fde60',
"recipients.userId" : "5789127ae2bcc79326462dbc"
},{
$set: {"recipients.$.read": true}
}).then(function(e) {
console.log(e)
}).catch(function(e) {
console.log(e);
});
我得到錯誤:
GeneralError: The positional operator did not find the match needed from the query. Unexpanded update: recipients.$.read
我在做什麼錯?
是否有一個更好的方法來更新許多消息一次?
謝謝!
有意義的我,但是當我運行這段代碼,我得到一個「錯誤:[對象對象]」響應 – tan
也許https://docs.feathersjs.com/debugging/readme.html可以幫助獲得更好的錯誤信息(可能是它不能正確轉換錯誤的錯誤)。 – Daff
需要使用補丁而不是更新。謝謝! – tan