반응형
Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

taenyLog

Mongoose | findByIdAndUpdate() 본문

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

 

반응형

'Web' 카테고리의 다른 글

async await 쓰는 이유  (0) 2023.06.29
Mongoose | findByIdAndDelete()  (0) 2023.06.29
Express Post 요청 접근  (0) 2023.06.28
http://localhost:3000 에러  (0) 2023.06.28
MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 에러 해결  (0) 2023.06.28