Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我不能在Mongodb3.4文本搜索中执行排序操作_Mongodb_Search_Text - Fatal编程技术网

为什么我不能在Mongodb3.4文本搜索中执行排序操作

为什么我不能在Mongodb3.4文本搜索中执行排序操作,mongodb,search,text,Mongodb,Search,Text,我跟着那页上的指南走 但当我在我的收藏(大约200万行)上建立文本索引并尝试搜索一些内容并按分数排序时,它会返回一个错误: Error: error: { "ok" : 0, "errmsg" : "Executor error during find command: OperationFailed: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify

我跟着那页上的指南走 但当我在我的收藏(大约200万行)上建立文本索引并尝试搜索一些内容并按分数排序时,它会返回一个错误:

Error: error: {
    "ok" : 0,
    "errmsg" : "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.",
    "code" : 96,
    "codeName" : "OperationFailed"
}

根据,如果mongoDB无法通过索引扫描获得排序顺序,它将使用一种算法来缓冲查询的前k个结果。如果内存占用超过32 MB,查询将失败,这正是您所经历的。尝试使用该方法限制扫描结果的数量。

@Tristan是正确的,但比使用limit更好的解决方案是先按分数过滤。通过使用limit,您可能无法获得记录集中的最高分数

例如,如果您的分数为100分,并且在执行排序之前,您对高分过滤器感兴趣

db.getCollection("myCollection").find(
  { 
    "score" : {
      "$gt" : 90
    }
  }
).sort(
  { 
    "score" : 1.0
  }
);