반응형
여러 $초로 쿼리를 그룹화하는 방법은?
아래와 같이 문의하고 싶은데, 이것은 하나만 포함하고 있습니다.$cond
.
2개로 질의하는 방법$cond
?
collection.aggregate(
{
$match : {
'_id' : {$in:ids}
}
},
{
$group: {
_id: '$someField',
...
count: {$sum: { $cond: [ { $eq: [ "$otherField", false] } , 1, 0 ] }}
}
},
function(err, result){
...
}
);
안에 복합 표현을 사용하려는 경우{$cond:[]}
- 다음과 같은 것.
collection.aggregate(
{
$match : {
'_id' : {$in:ids}
}
},
{
$group: {
_id: '$someField',
...
count: {$sum: { $cond: [ {$and : [ { $eq: [ "$otherField", false] },
{ $eq: [ "$anotherField","value"] }
] },
1,
0 ] }}
}
},
function(err, result){
...
}
);
연산자는 여기에 문서화되어 있습니다. http://docs.mongodb.org/manual/reference/operator/aggregation/ # boolean-
이와 같이 $초 안에 여러 개의 $초와 여러 개의 기준을 추가할 수 있습니다.'
collection.aggregate(
[
{
"$match": {
//matching criteria
}
},
{
"$project": {
"service": {
"$cond": {
"if": {
"$eq": [
"$foo",
"bar"
]
},
"then": "return string1",
"else": {
"$cond": {
"if": {
"$eq": [
"$foo",
"bar"
]
},
"then": "return string2",
"else": {
"$cond": {
"if": {
"$or": [
{
"$eq": [
"$foo",
"bar1"
]
},
{
"$eq": [
"$foo",
"bar2"
]
}
]
},
"then": "return string3",
"else": "$foo"
}
}
}
}
}
},
"_id": 0
}
}
]
)
`
언급URL : https://stackoverflow.com/questions/20836978/how-to-group-query-with-multiple-cond
반응형
'programing' 카테고리의 다른 글
아이폰 화면 중앙에 활동 표시기를 표시하는 방법은? (0) | 2023.10.02 |
---|---|
'HTMLMediaElement'에서 'play'를 실행하지 못함: API는 사용자 제스처로만 시작할 수 있습니다. (0) | 2023.10.02 |
AngularJS에서 node_modules 디렉토리란 무엇입니까? (0) | 2023.09.27 |
내부 표현으로 변환하지 못함 (0) | 2023.09.27 |
ajax success에서 부트스트랩 모드를 여는 방법 (0) | 2023.09.27 |