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