更新并返回新文档mongodb angularjs 2 typescript
我已将returnNewDocument修复为true,但仍保留旧文档,如何修复此问题更新并返回新文档mongodb angularjs 2 typescript,angular,typescript,Angular,Typescript,我已将returnNewDocument修复为true,但仍保留旧文档,如何修复此问题 public updateBestScore(scoreBD: ScoreBD, level: string): Promise<any> { return client.connect(url) .then( // Promesse tenue (db: any) => db.collection('
public updateBestScore(scoreBD: ScoreBD, level: string): Promise<any> {
return client.connect(url)
.then(
// Promesse tenue
(db: any) => db.collection('BEST_SCORES').findOneAndUpdate(
{ "level": level.toLowerCase, "bestScore.username": scoreBD.usernameBD },
{ $set: { "bestScore.$.score": scoreBD.score, "bestScore.$.username": scoreBD.usernamePlayer} },
{ returnNewDocument : true }
)
.then(
(res: any) => {
db.close();
console.log("resultat : ", res);
if (res.lastErrorObject.updatedExisting === true) {
console.log("resultat apres findOneAndUpdate : ", res.value.bestScore);
}
}),
// Promesse rompue
(err: any) => { throw "erreur"; });
}
public updateBestScore(scoreBD:scoreBD,level:string):承诺{
返回client.connect(url)
.那么(
//长女
(db:any)=>db.collection('BEST_SCORES')。findOneAndUpdate(
{“level”:level.toLowerCase,“bestScore.username”:scoreBD.usernameBD},
{$set:{“bestScore.$.score”:scoreBD.score,“bestScore.$.username”:scoreBD.usernamePlayer},
{returnNewDocument:true}
)
.那么(
(res:any)=>{
db.close();
日志(“resultat:”,res);
if(res.lastErrorObject.UpdateExisting==true){
console.log(“resultat apres findOneAndUpdate:,res.value.bestScore”);
}
}),
//龙佩议长
(err:any)=>{抛出“erreur”;});
}
添加一些关于您期望的内容和您面临的问题的描述我想更新我的收藏并返回新的更新收藏。但是该方法仍然在updatead comment to question之前返回旧集合