[MongoDB] 배열 $size 조건 $gt, $lt 조회

김택주·2023년 2월 6일

Mongo DB

목록 보기
6/9

출처: https://stackoverflow.com/questions/7811163/query-for-documents-where-array-size-is-greater-than-1/48410837#48410837

db.test.find({ testArr: { $size: 2 } });

size 2인 배열은 위와 같이 조회하면 되는데

size가 2보다 큰 2보다 작은 길이의 배열을 조회할때는

db.test.find({ testArr: { $size: { $gt: 2 } } });

위와 같이 하면 될꺼 같지만 안됨

db.test.find({$expr:{$gt:[{$size:{$ifNull:["$test1", []]}}, 1]}});

위 쿼리 실행시 가능
test1 사이즈가 1보다 큰 배열을 조회

0개의 댓글