문서 메뉴
문서 홈
/
MongoDB 매뉴얼
/ / /

$concatArrays (집계)

이 페이지의 내용

  • 정의
  • 행동
  • 예제
$concatArrays

버전 3.2에 새로 추가되었습니다.

배열을 연결하여 연결된 배열을 반환합니다.

$concatArrays 의 구문은 다음과 같습니다:

{ $concatArrays: [ <array1>, <array2>, ... ] }

<array> 표현식은 배열로 해석되는 한 유효한 표현식 이 될 수 있습니다. 표현식에 대한 자세한 내용은 표현식을 참조하세요 .

인수가 null 값으로 해석되거나 누락된 필드를 참조하는 경우 $concatArraysnull을 반환합니다.

예제
결과
{ $concatArrays: [
[ "hello", " "], [ "world" ]
] }
[ "hello", " ", "world" ]
{ $concatArrays: [
[ "hello", " "],
[ [ "world" ], "again"]
] }
[ "hello", " ", [ "world" ], "again" ]

다음 문서를 사용하여 warehouses 라는 이름의 샘플 collection을 생성합니다.

db.warehouses.insertMany( [
{ _id : 1, instock: [ "chocolate" ], ordered: [ "butter", "apples" ] },
{ _id : 2, instock: [ "apples", "pudding", "pie" ] },
{ _id : 3, instock: [ "pears", "pecans" ], ordered: [ "cherries" ] },
{ _id : 4, instock: [ "ice cream" ], ordered: [ ] }
] )

다음 예제에서는 instock와(과) ordered 배열을 연결합니다.

db.warehouses.aggregate( [
{ $project: { items: { $concatArrays: [ "$instock", "$ordered" ] } } }
] )
{ _id : 1, items : [ "chocolate", "butter", "apples" ] }
{ _id : 2, items : null }
{ _id : 3, items : [ "pears", "pecans", "cherries" ] }
{ _id : 4, items : [ "ice cream" ] }

다음도 참조하세요.

돌아가기

$concat

다음

$cond

이 페이지의 내용