연산자는 $comment 로그 및 프로파일러 출력에서 주석을 식별하는 데 도움이 되는 주석을 쿼리에 추가합니다. 이는 데이터베이스 작업을 디버깅하고 모니터링하는 데 특히 유용합니다.
문법
{
$comment: <string>
}
매개 변수
| 매개 변수 | Description |
|---|---|
string |
쿼리에 포함할 주석이 포함된 문자열입니다. |
예시
스토어 컬렉션에서 이 샘플 문서를 고려합니다.
{
"_id": "40d6f4d7-50cd-4929-9a07-0a7a133c2e74",
"name": "Proseware, Inc. | Home Entertainment Hub - East Linwoodbury",
"location": {
"lat": 70.1272,
"lon": 69.7296
},
"staff": {
"totalStaff": {
"fullTime": 19,
"partTime": 20
}
},
"sales": {
"totalSales": 151864,
"salesByCategory": [
{
"categoryName": "Sound Bars",
"totalSales": 2120
},
{
"categoryName": "Home Theater Projectors",
"totalSales": 45004
}
]
},
"promotionEvents": [
{
"eventName": "Massive Markdown Mania",
"promotionalDates": {
"startDate": {
"Year": 2023,
"Month": 6,
"Day": 29
},
"endDate": {
"Year": 2023,
"Month": 7,
"Day": 9
}
},
"discounts": [
{
"categoryName": "DVD Players",
"discountPercentage": 14
}
]
}
]
}
예제 1: 총 판매액이 100,000개가 넘는 매장을 찾고 참조용 로그 주석 추가
이 쿼리는 총 매출이 100,000개보다 큰 저장소를 검색하고 로그에서 쉽게 식별할 수 있는 주석을 포함합니다.
db.stores.find(
{ "sales.totalSales": { $gt: 100000 } },
{ name: 1, "sales.totalSales": 1 }
).comment("Query to find high-performing stores")
이 쿼리는 다음 결과를 반환합니다.
[
{
"_id": "40d6f4d7-50cd-4929-9a07-0a7a133c2e74",
"name": "Proseware, Inc. | Home Entertainment Hub - East Linwoodbury",
"sales": {
"totalSales": 151864
}
}
]