当前位置:首页 > IT科技

MongoDB排序时内存大小限制与创建索引的注意事项详解

线上服务的序时限制项详MongoDB中有一个很大的表,我查询时使用了sort()根据某个字段进行排序,内存结果报了下面这个错误:

[Error] Executor error during find command :: caused by :: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index,大小的注 or specify a smaller limit.

MongoDB排序时内存大小限制与创建索引的注意事项详解

at line 0, column 0

这是个非常常见的MongoDB报错了。因为MongoDB处理排序时,创建如果排序的亿华云计算索引字段没有建立索引,会把全表都丢到内存中处理。意事

MongoDB排序时内存大小限制与创建索引的注意事项详解

If MongoDB cannot use an index or 序时限制项详indexes to obtain the sort order, MongoDB must perform a blocking sort operation on the data. A blocking sort indicates that MongoDB must consume and process all input documents to the sort before returning results.

MongoDB排序时内存大小限制与创建索引的注意事项详解

而内存的大小并不是无限使用的,MongoDB的内存默认设置是32MB。高防服务器一旦数据量超过32MB,大小的注则会报错。创建

参数internalQueryExecMaxBlockingSortBytes

32MB这个限制是索引在参数internalQueryExecMaxBlockingSortBytes中控制。你可以在MongoDB的意事客户端上直接查看这个参数的值,执行以下语句:

?序时限制项详

源码下载

分享到:

滇ICP备2023006006号-16