Nested Document에 대한 Query
https://www.mongodb.com/docs/v4.4/tutorial/query-array-of-documents/f
Query an Array of Embedded Documents — MongoDB Manual
Docs Home → MongoDB Manual➤ Use the Select your language drop-down menu in the upper-right to set the language of the following examples.The following example selects all documents where an element in the instock array matches the specified document:Eq
www.mongodb.com
공식 문서는 이쪽
Nested Document속 Array 변형하기
https://www.mongodb.com/docs/manual/reference/operator/update-array/
Array Update Operators — MongoDB Manual
Docs Home → MongoDB ManualFor details on specific operator, including syntax and examples, click on the specific operator to go to its reference page.NameDescriptionActs as a placeholder to update the first element that matches the query condition.Acts a
www.mongodb.com
위와 같은 연산자를 활용.
Model.updateOne(
{ _id : exampleId },
{ $pull: {records : {_id : { $in : recordId}}}}
)
이는 아래와 같은 구조에서, records라는 Array 속 구성요소들 중 _id값이 recordId와 같은 구성요소(Object)를 삭제한다.

$pull과 같은 연산자는 위 문서에서
$in과 같은 옵션은 타 블로그를 참조함.
기타 연산자
$inc : 값을 증가시킴 (2초 페널티에 사용)
https://www.mongodb.com/docs/manual/reference/operator/update/inc/
$inc — MongoDB Manual
Docs Home → MongoDB Manual$incThe $inc operator increments a field by a specified value and has the following form:{ $inc: { : , : , ... } }To specify a in an embedded document or in an array, use dot notation.Starting in MongoDB 5.0, update operators pr
www.mongodb.com
그외에도 set unset등등..
'Coding > React' 카테고리의 다른 글
| Cannot GET (express) (0) | 2022.08.18 |
|---|---|
| 큐뱃 개발 - 2022.08.02 (0) | 2022.08.04 |
| 큐뱃 개발 - heroku 업로드 (0) | 2022.08.01 |
| 큐뱃 개발 - 구글 로그인 (2022.07.28~29) (0) | 2022.07.30 |
| 큐뱃 개발 - MongoDB 관련 (0) | 2022.07.25 |