-
MongoDB Aggregation스터디노트/DB 2022. 5. 10. 14:54
$arrayElemAt
- 배열의 특정 인덱스에 있는 값을 리턴한다.
- yourField의 0번째 인덱스의 값을 리턴
{ $arrayElemAt: ['$yourCollection.yourField', 0] }
$ifNull
- 배열의 특정 인덱스에 있는 값을 리턴한다.
- yourField의 0번째 인덱스의 값이 null인 경우 ' '을 리턴
{ $ifNull: [{ $arrayElemAt: ['$yourCollection.yourField', 0] }, ' '] }
참고자료
- MongoDB Aggregation : https://www.mongodb.com/docs/manual/reference/operator/aggregation/
'스터디노트 > DB' 카테고리의 다른 글
MongoDB 사칙연산 쿼리 (0) 2022.07.04 MongoDB 필드를 참조하여 업데이트 하기 (0) 2022.06.16 mongoose.Schema : default: () => [] (0) 2022.05.09 mongoDB compass에서 간단한 쿼리 날려보기 (Aggregate, $match, $project, $expr, $lookup, ...) (0) 2022.04.22 new mongoose.Schema VS mongoose.Schema (0) 2022.04.18