Await in Nestjs Mongoose Update/Delete

Viewed 607

Hy all. Why article.service.ts without "await" doesn't persist update/delete to mongodb?

article.service.ts

async update(id: string, updateArticleDto: UpdateArticleDto) {    
  await this.articleModel.updateOne({_id: id}, updateArticleDto);        
}

async remove(id: string) {
  await this.articleModel.deleteOne({_id: id});     
}

Thank you all

1 Answers

Because updateOne and deleteOne are asynchronous functions, and we use await to wait for a promise to resolve the result. for more details check this article

Related