node程序,使用mongoose,排序查询中报错如下:
message=errmsg: "Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit.", name=MongoError, stack=MongoError: errmsg: "Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit."
问题原因:
当数据量大时,内存中排序,导致内存溢出。
解决思路:
增加mongodb可以使用的内存。或者在排序字段上添加索引。
使用语句:
db.collection.getIndexes()
db.collection.createIndex({"field": -1})