정의
$toLower
문자열을 소문자로 변환하여 결과를 반환합니다.
$toLower
의 구문은 다음과 같습니다:{ $toLower: <expression> } 인수는 로 해석되는 한 모든 표현식 이 될수 string 있습니다. 표현식에 대한 자세한 내용은 표현식 연산자를 참조하세요.
인수가 null로 해석되면
$toLower
가 빈 문자열""
를 반환합니다.
행동
$toLower
는 ASCII 문자의 문자열에 대해서만 잘 정의된 동작을 보유합니다.
예시
다음 문서가 포함된 inventory
collection을 생각해 보세요.
db.inventory.insertMany( [ { _id: 1, item: "ABC1", quarter: "13Q1", description: "PRODUCT 1" }, { _id: 2, item: "abc2", quarter: "13Q4", description: "Product 2" }, { _id: 3, item: "xyz1", quarter: "14Q2", description: null } ] )
다음 연산은 $toLower
연산자를 사용하여 item
, description
값을 소문자로 반환합니다.
db.inventory.aggregate( [ { $project: { item: { $toLower: "$item" }, description: { $toLower: "$description" } } } ] )
이 연산은 다음과 같은 결과를 반환합니다.
{ _id: 1, item: "abc1", description: "product 1" } { _id: 2, item: "abc2", description: "product 2" } { _id: 3, item: "xyz1", description: "" }