Web

Mongoose | findByIdAndUpdate()

taenyLog 2023. 6. 29. 06:19
반응형

findByIdAndUpdate() 함수는 일치하는 문사를 찾고 , 업데이트 인수에 따라 업데이트하고,옵션을 전달하고 , 찾은 문서를 콜백에 반환하는데 사용

 

 

 

Issues a mongodb findOneAndUpdate command by a document's _id field. findByIdAndUpdate(id, ...) is equivalent to findOneAndUpdate({ _id: id }, ...).

Finds a matching document, updates it according to the update arg, passing any options, and returns the found document (if any).

This function triggers the following middleware.

  • findOneAndUpdate()

Example:

A.findByIdAndUpdate(id, update, options)  // returns Query
A.findByIdAndUpdate(id, update)           // returns Query
A.findByIdAndUpdate()                     // returns Query

 

 

 

 

https://mongoosejs.com/docs/api/model.html#Model.findByIdAndUpdate() 

 

Mongoose v7.3.1: Model

Parameters: doc «Object» values for initial set [fields] «Object» optional object containing the fields that were selected in the query which returned this document. You do not need to set this parameter to ensure Mongoose handles your query projection

mongoosejs.com

 

반응형