mongo添加索引以及解决Sort operation used more than the maximum 33554432 bytes of RAM
来源:互联网 发布:江苏普通发票软件下载 编辑:程序博客网 时间:2024/05/21 17:58
在 mongo 使用过程中遇到了一个问题,需求就是要对mongo 库中查询到数据进行分页,mongo库我们知道都会存储大容量的数据,刚开始使用的 skip 和 limit 联合使用的方法,来达到截取所需数据的功能,这种方法在库里数据容量小的情况下完全可以胜任,但是如果库里数据多的话,上面两个方法就不好使了,就像题目中那个错误,这时会报一个 Query failed with error code 96 and error message 'Executor error during find command:OperationFailed: Sort operation used more than the maximum 33554432 bytes of RAM.Add an index, or specify a smaller limit.'
按照错误提示,知道这是排序的时候报的错,因为 mongo 的 sort 操作是在内存中操作的,必然会占据内存,同时mongo 内的一个机制限制排序时最大内存为 32M,当排序的数据量超过 32M,就会报上面的这个错,解决办法就像上面提示的意思,一是加大 mongo 的排序内存,这个一般是运维来管,也有弊端,就是数据量如果再大,还要往上加。另一个办法就是加索引,这个方法还是挺方便的。创建索引及时生效,不需要重启服务。
创建索引也不难,
db.你的collection.createIndex({"你的字段": -1}),此处 -1 代表倒序,1 代表正序;
db.你的collecton.getIndexes();
这两个语句,第一个是添加索引,第二个是查询索引,如果查看到你刚才添加的那个索引字段,就说明索引添加成功了。这时候在你的程序里再运用 sort 方法的话,这样就不会报错而且速度很快。
添加索引会带来一定的弊端,这样会导致数据插入的时候相对之前较慢,因为索引会占据空间的。综上考虑,根据实际情况判断采用合适的方法。
- mongo添加索引以及解决Sort operation used more than the maximum 33554432 bytes of RAM
- Sort operation used more than the maximum 33554432 bytes of RAM
- 遇到错误----Mongodb----导出数据报错 Sort operation used more than the maximum 33554432 bytes of RAM
- MySQL创建索引抛出“required more than 'innodb_online_alter_log_max_size' bytes of modification log”异常的解决方案
- Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage
- statement transaction required more than 'max_binlog_cache_size' bytes of storage
- JBWEB002004: More than the maximum number of request parameters (GET plus POST) for a single request
- The stack 'CSTACK' is filled to 100% (4096 bytes used out of 4096) 错误解决
- Introduction to Flash Memory -- It is used more as a hard drive than as RAM.
- 解决used as the name of the previous parameter rather than as part of the selector方法
- 解决used as the name of the previous parameter rather than as part of the selector(⚠️)方法
- warning: the frame size of 1104 bytes is larger than 1024 bytes [-Wframe-larger-than=]
- Apache Tomcat哈希碰撞拒绝服务漏洞解决办法 or More than the maximum number of request parameters (GET plus POST)
- 解决IDEA This version of the rendering library is more recent than your version of IntelliJ IDEA. Plea
- update语句报错 statement transaction required more than 'max_binlog_cache_size' bytes of storage
- warning: the frame size of 1456 bytes is larger than 1024 bytes
- warning: the frame size of 1040 bytes is larger than 1024 bytes
- warning: the frame size of 1040 bytes is larger than 1024 bytes
- Androidstudio 快速生成常用的代码块儿的缩写汇总
- vijos1250 最勇敢的机器人
- ionic2长列表返回顶端控件的一个简单实现
- 高仿APP——元贝驾考
- LeetCode 476 Number Complement
- mongo添加索引以及解决Sort operation used more than the maximum 33554432 bytes of RAM
- Oracle数据库创建新用户并授予DBA权限
- 机器学习和图像处理(opencv)专用英语词典
- add-two-numbers
- docker ui 部署
- 利用Immutable解决React-Native那些因为对象被篡改导致的多次render问题
- Dijkstra算法求单源最短路径Java实现
- python识别图片验证码
- 解决flash插件被谷歌屏蔽