참고 : https://docs.mongodb.com/manual/tutorial/query-embedded-documents/
Query on Embedded/Nested 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.For example, the following query selects all documents where the field size equals the document { h: 14, w: 21, uom
docs.mongodb.com
포함/중첩 document에 대한 Query
- 포함/중첩 document 일치document{ : }를 사용한다. 여기서 는 일치시킬 document이다.
- 포함/중첩된 document에 사용되는 필드에 동등 조건을 지정하려면 쿼리 필터
ex) inventory 컬렉션의 size 필드가 equals the document { h: 14, w: 21, uom: "cm" }
:
db.inventory.find( { size: { h: 14, w: 21, uom: "cm" } } )
- 중첩 field에 대한 쿼리포함/중첩 document에 대한 쿼리
포함/중첩 document 필드에 쿼리 조건을 지정하려면 점 표기법을 사용한다.
dot notation ("field.nestedField"
).
<참고> → 점 표기법을 사용하여 쿼리할 때 필드와 중첩 필드는 따옴표 안에 있어야 합니다.
ex) size 필드에 중첩된 uom 필드에 “in”인 모든 document 선택
db.inventory.find( { "size.uom": "in" } )
ex) size 필드에 중접된 h 필드에 less than operator 인 $lt을 사용해서 선택
db.inventory.find( { "size.h": { $lt: 15 } } )
ex) AND 연산자 사용한 검색
db.inventory.find( { "size.h": { $lt: 15 }, "size.uom": "in", status: "D" } )
'Database > MongoDB' 카테고리의 다른 글
MongoDB - 배열 쿼리 - (2) (0) | 2021.12.19 |
---|---|
MongoDB - 배열 쿼리 - (1) (0) | 2021.12.19 |
MongoDB - Document Query(조회) - (1) (0) | 2021.12.18 |
MongoDB - Database/Collection/Document생성,제거 (0) | 2021.12.18 |
MongoDB - 데이터 모델링 (0) | 2021.12.18 |