gpt4 book ai didi

mongodb - MongoDB 2.6 排序查询的最大限制

转载 作者:可可西里 更新时间:2023-11-01 09:31:18 28 4
gpt4 key购买 nike

使用 mongo 排序对 200 万条记录进行排序是否可行?

从MongoDB Documentation中明确提到“当排序操作消耗超过32兆字节时,MongoDB返回错误。”

但是我需要对大量记录进行排序。怎么做?

最佳答案

这是可能的。文档指出,只有当 MongoDB 在内存中对数据进行排序时,即不使用索引时,才会有 32MB 的限制。

When the sort operation consumes more than 32 megabytes, MongoDB returns an error. To avoid this error, either create an index to support the sort operation or use sort() in conjunction with limit(). The specified limit must result in a number of documents that fall within the 32 megabyte limit.

我建议您使用ensureIndex 命令在要排序的字段上添加索引:

db.coll.ensureIndex({ sortFieldName : 1});

如果您在多个字段上排序,您将需要添加 compound index在您排序的字段上(索引中的字段顺序很重要):

db.coll.ensureIndex({ sortFieldName1 : 1, sortFieldName2 : 1});

关于mongodb - MongoDB 2.6 排序查询的最大限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24353917/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com