FilteredAccording 部分和categorizedBy 使用我在链接中提供的查询按预期工作,但我在 findDistinct 部分遇到问题。
在 mongodb 中我有以下数据:
{
"_id": 10001,
"university": "SPYU",
"Courses": [
"English",
"French"
],
"dept": [
"Literature"
],
"type": [
"Autonomous"
],
"status": "ACTIVE",
"isMarked": true
},
{
"_id": 10002,
"university": "SPYU",
"Courses": [
"English",
"French"
],
"dept": [
"Literature"
],
"type": [
"Autonomous"
],
"status": "NON-ACTIVE",
"isMarked": true
}
我希望得到的回应是:
"university": [
{
"name": "Literature",
"values": [
{
"_id": 10001,
"university": "SPYU",
"Courses": [
"English",
"French"
],
"dept": [
"Literature"
],
"type": [
"Autonomous"
],
"status": "ACTIVE",
"isMarked": true
},
{
"_id": 10002,
"university": "SPYU",
"Courses": [
"English",
"French"
],
"dept": [
"Literature"
],
"type": [
"Autonomous"
],
"status": "NON-ACTIVE",
"isMarked": true
}
]
}
],
"findDistinct": [
{
"name": "Courses",
"values": [
"English",
"French"
]
},
{
"name": "Status",
"values": [
"ACTIVE",
"NON-ACTIVE"
]
}
]
我使用此链接进行了尝试,但响应并未按预期进行。https://mongoplayground.net/p/XECZvRMmt3T https://mongoplayground.net/p/XECZvRMmt3T
现在,回应是这样的
"universities": [
{
"name": "Literature",
"values": [
{
"_id": 10001,
"university": "SPYU",
"Courses": [
"English",
"French"
],
"dept": [
"Literature"
],
"type": [
"Autonomous"
],
"status": "ACTIVE",
"isMarked": true
},
{
"_id": 10002,
"university": "SPYU",
"Courses": [
"English",
"French"
],
"dept": [
"Literature"
],
"type": [
"Autonomous"
],
"status": "NON-ACTIVE",
"isMarked": true
}
]
}
],
"findDistinct": [
{
"Courses": [
"English",
"French"
]
},
{
"status": [
"ACTIVE",
"NON-ACTIVE"
]
}
]
任何帮助将不胜感激!!