mongodb - Mongoose如何按嵌入式数组的总和排序
问题描述
我有一个课程集合,其中的一个数组存储课程等级 1-5 的计数。如 [0, 3, 0, 0, 1] 表示 3 人投 2 星,1 人投 5 星。如何使用猫鼬按最终分数排序?我的意思是先计算 (a + 2b + 3c + 4d + 5e) / (a + b + c + d + e) 作为分数,然后对集合进行排序?</p>
const CourseSchema = new mongoose.Schema({
courseName: {
type: String,
required: true
},
rateCount: {
type: [Number],
required: true,
default: [0, 0, 0, 0, 0]
}
}
解决方案
推荐阅读
- bing - 必应搜索 API v7 分页
- sql - 在天蓝色云中的数据库中执行时,sql 查询无法正常工作
- javascript - responseType blob 有效,但不是 Ajax 的新 Blob
- javascript - 如何从 Web 程序集获取数据到 JavaScript?
- wpf - WPF CustomControl 样式中的子项更改?
- azure - 无法将 network_interface_id 解析为资源 id:无法解析 AzureID:解析 module.network.azurerm_network_interface.primary.id: invalidURIforrequest
- python - Django 异常
- powershell - PowerShell - 基于比较 2 个对象并查找不匹配项
- anylogic - 从多个来源中选择输入
- python - pandas pct_change(),按国家分组数据索引日期给出不正确的结果