# MongoDB 몽고디비 array 조회, 테이블 표기 방법

**URL:** <https://ask.selectfromuser.com/t/mongodb-array/79>\
**Category:** 자유게시판\
**Tags:** array, mongodb\
**Created:** [10월 2, 2023, 3:57오후 UTC](https://ask.selectfromuser.com/t/mongodb-array/79 "2023-10-02T15:57:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hbkim](https://yyz2.discourse-cdn.com/flex032/user_avatar/ask.selectfromuser.com/hbkim/32/23_2.png) [@hbkim](https://ask.selectfromuser.com/u/hbkim)\
**Post date:** [10월 2, 2023, 3:57오후 UTC](https://ask.selectfromuser.com/t/mongodb-array/79/1 "2023-10-02T15:57:09Z")

</div>

임베디드 다큐먼트(embedded document)의 타입이 배열 array일 때

기본적인 MongoDB 몽고디비 쿼리로는 구조상 쉽게하는데 한계가 있어

셀렉트에서 변환하는 방법을 안내드립니다.

**\<참고 이미지와 YAML 코드\>**

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/selectfromuser/original/1X/7f1e37d151814cc4c178e1d6d4487c0148cd0153.png)

케이스

1. 일반적으로 콜렉션을 조회할 때
2. 각 row의 name.value를 테이블로 조회하는 방법
3. 여러 name.value 들을 한 row에 표기하는 방법

```yaml
      - type: query        
        resource: mongodb
        name: 1
        sqlType: select
        query:
          collection: nested
          find:        

      - type: query
        resource: mongodb
        name: 2
        sqlType: select
        responseRowFn: |
          row.data = row.data.embed.name
        query:
          collection: nested
          aggregate:
            - $unwind: $data.embed
            - $group:
                _id: $_id

      - type: query
        resource: mongodb
        name: 3
        sqlType: select
        responseRowFn: |
          row.data = row.data.embed.map(e => e.name).join(', ')
        query:
          collection: nested
          find:
            - {}
            - projection:
                _id: 1
                data: 1

```
