【问题标题】:Limit and sort inline Map/Reduce in MongoDB在 MongoDB 中限制和排序内联 Map/Reduce
【发布时间】:2012-02-09 19:58:34
【问题描述】:

据我所知,我无法在 Mongo 中指定复杂的排序函数,因此我必须使用 map/reduce 查询,这感觉有点没用,因为我什至不使用 reduce 部分。这很好,但它返回的集合太大,我需要对其进行排序和限制(分页)。是否可以通过内联调用来做到这一点?我无法存储生成的集合然后对其进行查询,因为该集合对每个用户都是唯一的并且不断变化。

【问题讨论】:

    标签: mongodb


    【解决方案1】:

    通常 sort 在 mongodb mapreduce 中应用在映射之前,实际上它们是应用于输入数据而不是输出。

    来自 mongodb 文档

       [, sort : <sorts the input objects using this key. Useful for optimization, like sorting by the emit key for fewer reduces>]
       [, limit : <number of objects to return from collection>]
    

    因此,如果您想对 map reduce 输出进行排序和限制,则必须将结果存储在临时集合中。我认为不可能将排序和限制应用于inline mapreduce 输出,因为它在 RAM 上运行。

    编辑:

    在 mongodb Jira 中有一个未解决的问题 (Add support for sorting and limiting inline map/reduce) 与此有关。看看吧。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多