2016-09-18 7 views
0

メッセージが特定のIDを持ち、ユーザーIDが受信者配列にあるサブ文書の値を更新します。一致したオブジェクトの値を指定されたユーザーIDで更新したいとします。FeathersJS Mongoose:一致するサブ文書を更新できません。

私はMongoDBのCLIで次のクエリを実行すると、すべてが動作し、値が更新されます。

db.getCollection('messages').update({ 
    _id : ObjectId("57d7edb8c497a75a6a7fde60"), 
    "recipients.userId" : "5789127ae2bcc79326462dbc" 
},{ 
    $set : {"recipients.$.read": true} 
}); 

しかし、私は私のFeathersJSアプリケーションでJSを経由して次のクエリを実行します。

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

私は間違っていますか?

一度に多くのメッセージを更新する良い方法がありますか?

ありがとうございました!あなたはnullidを設定し、params.queryにクエリを置くことによってservice methodを呼び出す必要があるクエリで一つまたは複数のレコードを更新するための

答えて

1

messageService.update(null, { 
    $set: {"recipients.$.read": true} 
}, { 
    query: { 
    _id : '57d7edb8c497a75a6a7fde60', 
    "recipients.userId" : "5789127ae2bcc79326462dbc" 
    } 
}).then(function(e) { 
    console.log(e) 
}).catch(function(e) { 
    console.log(e); 
}); 
+0

は私のために理にかなっているが、私はこのコードを実行するとき、私は取得"エラー:[オブジェクトオブジェクト]"の応答 – tan

+1

https://docs.feathersjs.com/debugging/readme.htmlがエラーを正しく表示するのに役立つかもしれません(エラーを正しく変換していないバグかもしれません)。 – Daff

+0

更新プログラムの代わりに更新プログラムを使用する必要がありました。ありがとう! – tan

関連する問題