mongodb - MongoDB,按经常更新的字段对大集合进行排序
问题描述
我有这个模式(使用 nodejs - mongoose):
const Post = new mongoose.Schema({
title: {
type: String,
required: true,
unique: true,
},
description: {
type: String,
required: true,
},
likes: {
type: Number,
required: true,
default: 0,
min: 0,
}
}, {
timestamps: true,
});
假设我的收藏有数百万个这样的文档,我想按“喜欢”排序。同时,“喜欢”是非常频繁更新的东西,所以我认为我不应该在上面使用排序索引。如果我使用排序和限制在分页中提供该内容,即使我不使用索引,这是否保证我在读取数据时具有良好的性能?(我知道mongo默认使用一些算法来创建内存桶对数据进行排序,当没有提供索引时)
解决方案
推荐阅读
- java - 无法延迟加载集合 - 在哪里重新附加?
- mongodb - 如何为使用mongodb进行数据持久化的spring boot rest控制器编写Junit测试用例
- mysql - 如何在一行中存储多个ID?
- hive - 如何使用 PySpark 更新 hive 表中的记录?
- amazon-web-services - AWS 托管集群(不是 EKS)上的 Kubernetes:基础设施复制逻辑在哪里?
- javascript - React 高阶组件:添加实例方法的正确方法
- concurrency - 如何处理对 Citrus 服务器上不同 URL 的并行请求?
- python - 每当我尝试将数字数据写入我的 .txt 文件时,它都会引发错误
- c - 使用cantools生成的C文件
- angular - 等待多个观察者完成