错误如下:
在mongodb分页查询 页码过大时:
Query failed with error code 292 and error message ‘Executor error during find command :: caused by :: Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in.’ on server xxx:27017; nested exception is com.mongodb.MongoQueryException: Query failed with error code 292 and error message ‘Executor error during find command :: caused by :: Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in.’ on server xxx:27017
错误原因:
mongodb默认排序内存为32M,超出索引内存,抛出异常
解决方案创建索引
进入docker mongo内部
docker exec -it mongo /bin/bash
选择数据库
use admin
登录
db.auth(“kngdommongo”,”kingdom123456″);
创建索引
db.feer.mqtt.data.createIndex({ “createTime” : -1 })
查看索引
db.feer.mqtt.data.getIndexes()
删除索引
db.feer.mqtt.data.dropIndex(“createTime_-1”)